Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support SONiC OpenSSL FIPS 140-3 based on SymCrypt engine #9573

Merged
merged 8 commits into from
May 5, 2022

Conversation

xumia
Copy link
Collaborator

@xumia xumia commented Dec 17, 2021

Why I did it

Support OpenSSL FIPS 140-3, see design doc: https://github.com/Azure/SONiC/blob/master/doc/fips/SONiC-OpenSSL-FIPS-140-3.md.

How I did it

Install the fips packages.
To build the fips packages, see https://github.com/Azure/sonic-fips
Azure pipelines: https://dev.azure.com/mssonic/build/_build?definitionId=412

How to verify it

Validate the SymCrypt engine:

admin@sonic:~$ dpkg-query -W | grep openssl
openssl 1.1.1k-1+deb11u1+fips
symcrypt-openssl        0.1

admin@sonic:~$ openssl engine -v | grep -i symcrypt
(symcrypt) SCOSSL (SymCrypt engine for OpenSSL)
admin@sonic:~$ 

Install debug version of symcrypt and validate:

$ gdb --args openssl rand 10 
(gdb) b scossl_rand_bytes
(gdb) r
Starting program: /usr/bin/openssl rand 10

Breakpoint 1, scossl_rand_bytes (buf=0x7ffd81ce49f0 "200\024\t\300\004X\020\211\263!", num=10)
    at /src/SymCrypt-OpenSSL/SymCryptEngine/src/scossl_rand.c:23
23          SymCryptRandom(buf, num);

Test golang: when the fips is enabled, the test.go will call go boring api, call openssl api, and then call symcrypt api.

test.go:
import (
    "crypto/rand"
    "crypto/rsa"
)
func main() {
    rsa.GenerateKey(rand.Reader, 2048)
}
$ gdb test
(gdb) b scossl_rsa_keygen
(gdb) r
Thread 1 "test" hit Breakpoint 1, scossl_rsa_keygen (rsa=0x12299b0, bits=2048, e=0x122e490, cb=0x0) at /src/SymCrypt-OpenSSL/SymCryptEngine/src/scossl_rsa.c:638
638         PBYTE   ppbPrimes[2] = { 0 };

(gdb) bt
#0  scossl_rsa_keygen (rsa=0x12299b0, bits=2048, e=0x122e490, cb=0x0) at /src/SymCrypt-OpenSSL/SymCryptEngine/src/scossl_rsa.c:638
#1  0x00007f4e966a8446 in RSA_generate_key_ex (rsa=0x12299b0, bits=2048, e_value=0x122e490, cb=0x0) at ../crypto/rsa/rsa_gen.c:35
#2  0x00000000004025aa in crypto/internal/boring(.text) ()
...
#8  0x0000000000401c0e in _cgo_b67541c0c44c_Cfunc__goboringcrypto_RSA_generate_key_fips ()

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106

Description for the changelog

A picture of a cute animal (not mandatory but encouraged)

rules/sonic-fips.mk Outdated Show resolved Hide resolved

SYMCRYPT_OPENSSL_NAME = symcrypt-openssl
SYMCRYPT_OPENSSL = fips/$(SYMCRYPT_OPENSSL_NAME)_$(FIPS_VERSION)_$(CONFIGURED_ARCH).deb
$(SYMCRYPT_OPENSSL)_SRC_PATH = $(SRC_PATH)/sonic-fips
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonic-fips

Do you want to add a new submodule in this PR? #Closed

Copy link
Collaborator Author

@xumia xumia Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we will use binaries only, it will take long time to build it.
And the module SymCryptDependencies is microsoft only (to test only), not available by public, see https://github.com/microsoft/SymCrypt/blob/0f83207858253be11f473dced88b146895004419/.gitmodules#L3
We do not have hard the dependency on the submodule, it can be skipped during the build. We will have a trouble if using it, cannot checkout code recursively.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If these packages need to be updated (for fixing security issues, or features/functionality), is there an easy way to rebuild the FIPS packages?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, see https://github.com/Azure/sonic-fips.
I will add the artifacts publish automation later, currently, copy the artifacts to storage container manually.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which storage? Do you mean FIPS_URL_PREFIX? I notice the name difference: sonic-fips vs fips.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the same some of the other artifacts, sonicstorage.

Makefile.work Outdated Show resolved Hide resolved
slave.mk Outdated Show resolved Hide resolved
@@ -397,6 +397,13 @@ RUN sudo augtool --autosave "set /files/etc/dpkg/dpkg.cfg/force-confold"
RUN apt-get -y build-dep linux

# For gobgp and telemetry build
{%- if INCLUDE_FIPS == "y" %}
RUN wget -O golang-go.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/0.1/golang-1.15-go_1.15.15-1~deb11u2%2Bfips_{{ CONFIGURED_ARCH }}.deb' \
Copy link
Collaborator

@qiluo-msft qiluo-msft Dec 21, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1.15

RUN wget -O golang-go.deb 'https://sonicstorage.blob.core.windows.net/public/fips/bullseye/0.1/golang-1.15-go_1.15.15-1~deb11u2%2Bfips_{{ CONFIGURED_ARCH }}.deb' \


Can we use the same version as in else branch? Ideally, we should share the version constant, and build any version specified with FIPS. #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change all to use 1.15 for bullseye, align to the default one in bullseye.
And change to use the debian packages, not to download from google web site.

@xumia
Copy link
Collaborator Author

xumia commented Dec 24, 2021

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xumia
Copy link
Collaborator Author

xumia commented Dec 25, 2021

/azp run

@azure-pipelines
Copy link

You have several pipelines (over 10) configured to build pull requests in this repository. Specify which pipelines you would like to run by using /azp run [pipelines] command. You can specify multiple pipelines using a comma separated list.

@xumia
Copy link
Collaborator Author

xumia commented Dec 25, 2021

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xumia xumia force-pushed the support-symcrypt-fips-1 branch 2 times, most recently from e5e9ac3 to 1905773 Compare January 21, 2022 05:53
@xumia
Copy link
Collaborator Author

xumia commented Feb 18, 2022

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xumia
Copy link
Collaborator Author

xumia commented Feb 18, 2022

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@xumia xumia force-pushed the support-symcrypt-fips-1 branch 4 times, most recently from 1a76fd6 to 34d2e14 Compare April 2, 2022 15:01
@xumia xumia force-pushed the support-symcrypt-fips-1 branch 2 times, most recently from 39bb11b to a970b1e Compare April 22, 2022 23:37
@xumia xumia changed the title Support symcrypt crypto module for fips Support SONiC OpenSSL FIPS 140-3 based on SymCrypt engine Apr 22, 2022
@xumia xumia force-pushed the support-symcrypt-fips-1 branch 2 times, most recently from 4619899 to 152115f Compare April 27, 2022 09:06
@xumia xumia marked this pull request as ready for review April 28, 2022 14:21
@xumia
Copy link
Collaborator Author

xumia commented Apr 29, 2022

@qiluo-msft , @saiarcot895 , could you please help review again?

slave.mk Outdated Show resolved Hide resolved
# Remove sshd host keys, and will regenerate on first sshd start. This needs to be
# done again here because our custom version of sshd is being installed, which
# will regenerate the sshd host keys.
sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key*
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 29, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why move this statement? #Closed

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When installing openssl/openssh for fips, the ssh key will be generated again, so moving the removal step after all installing steps are complete.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As my understanding, in original code, removal step is after all openssl/openssh installing steps.

If you have a good reason, is it a general bug fix?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a bug, there is an additional installation step to install debian packages, the FIPS packages are installed in the step, see https://github.com/Azure/sonic-buildimage/blob/53e5fe6a93b051c8319d51e109d317beb5166e77/files/build_templates/sonic_debian_extension.j2#L598

We move the removal step, because the FIPS packages will generate the ssh keys again.

# Add extra linux command line
extra_cmdline_linux=%%EXTRA_CMDLINE_LINUX%%
echo "EXTRA_CMDLINE_LINUX=$extra_cmdline_linux"
ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="$ONIE_PLATFORM_EXTRA_CMDLINE_LINUX $extra_cmdline_linux"
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ONIE_PLATFORM_EXTRA_CMDLINE_LINUX

ONIE_PLATFORM_EXTRA_CMDLINE_LINUX="$ONIE_PLATFORM_EXTRA_CMDLINE_LINUX $extra_cmdline_linux"


Do not combine %%EXTRA_CMDLINE_LINUX%% with ONIE_PLATFORM_EXTRA_CMDLINE_LINUX. Just add %%EXTRA_CMDLINE_LINUX%% to below menuentry template. #Closed

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, by semantics, GRUB_CMDLINE_LINUX should include %%EXTRA_CMDLINE_LINUX%%

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, fixed, better to use GRUB_CMDLINE_LINUX .

rules/config Outdated Show resolved Hide resolved
@xumia
Copy link
Collaborator Author

xumia commented May 1, 2022

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Collaborator

@qiluo-msft qiluo-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please check with other reviewers.

@xumia
Copy link
Collaborator Author

xumia commented May 5, 2022

@saiarcot895 , could you please help review it again? Thanks.

@xumia xumia merged commit 8ec8900 into sonic-net:master May 5, 2022
@xumia xumia deleted the support-symcrypt-fips-1 branch May 5, 2022 23:21
liushilongbuaa pushed a commit to liushilongbuaa/sonic-buildimage that referenced this pull request Jun 20, 2022
…9573)

Why I did it
Support OpenSSL FIPS 140-3, see design doc: https://github.com/Azure/SONiC/blob/master/doc/fips/SONiC-OpenSSL-FIPS-140-3.md.

How I did it
Install the fips packages.
To build the fips packages, see https://github.com/Azure/sonic-fips
Azure pipelines: https://dev.azure.com/mssonic/build/_build?definitionId=412

How to verify it
Validate the SymCrypt engine:

admin@sonic:~$ dpkg-query -W | grep openssl
openssl 1.1.1k-1+deb11u1+fips
symcrypt-openssl        0.1

admin@sonic:~$ openssl engine -v | grep -i symcrypt
(symcrypt) SCOSSL (SymCrypt engine for OpenSSL)
admin@sonic:~$
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants