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 running CCF on Azure Linux #6588

Open
3 tasks done
maxtropets opened this issue Oct 23, 2024 · 18 comments
Open
3 tasks done

Support running CCF on Azure Linux #6588

maxtropets opened this issue Oct 23, 2024 · 18 comments
Assignees

Comments

@maxtropets
Copy link
Collaborator

maxtropets commented Oct 23, 2024

In this issue have to support building and testing CCF on Azure Linux.

The major obstacle so far - openssl.

On Azure Linux, we shall use OpenSSL of (major) version 3. It is to be determined in this ticket which exact version is supported by Azure Linux.

Ticket for reference: #5291

Subtasks to track the progress

  • Try fix ./crypto_test (patched, see discussions in comments)
  • What backend is used in Azure Linux? SymCrypt? Prove by tracking the lib we link against
  • breakdown initial issues
@maxtropets maxtropets self-assigned this Oct 23, 2024
@achamayou
Copy link
Member

achamayou commented Oct 23, 2024

@maxtropets current is 3.3.2, so that one :)

@maxtropets maxtropets changed the title Upgrade OpenSSL to v.3+ Solve OpenSSL on Azure Linux Oct 25, 2024
@maxtropets
Copy link
Collaborator Author

Currently removed the SECP256K1 curve from crypto_test, fails on EVP_PKEY_CTX_set_ec_paramgen_curve_nid with err = 0.

Checked OpenSSL source, same NID for 3.1 and 3.3 impl, NID matches.

#define NID_secp256k1           714

Needs investigation.

@maxtropets
Copy link
Collaborator Author

maxtropets commented Oct 25, 2024

Tried all other unit tests (crypto test patched with #6591)

 ./tests.sh -VV -L unit
...
The following tests FAILED:
	 11 - crypto_test (Failed)
	 13 - key_exchange_test (SEGFAULT)
	 18 - endorsements_test (Failed)
	 19 - historical_queries_test (SEGFAULT)
	 21 - snapshotter_test (SEGFAULT)
	 27 - channels_test (SEGFAULT)
	 28 - http_test (Failed)
	 37 - csr_test (Failed)

@achamayou
Copy link
Member

256k1 is not a NIST standard, which is likely why SymCrypt rejects it - it would be good to confirm and document though

@maxtropets
Copy link
Collaborator Author

What backend is used in Azure Linux? SymCrypt? Prove by tracking the lib we link against

Figured out it's not explicitly linked, but rather being loaded during runtime

openat(AT_FDCWD, "/usr/lib/libsymcrypt.so.103", O_RDONLY|O_CLOEXEC) = 3
read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\0\0\0\0\0\0\0\0"..., 832) = 832
newfstatat(3, "", {st_mode=S_IFREG|0755, st_size=778048, ...}, AT_EMPTY_PATH) = 0
mmap(NULL, 557528, PROT_READ, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x7f2af8423000
mmap(0x7f2af842f000, 380928, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0xc000) = 0x7f2af842f000
mmap(0x7f2af848c000, 118784, PROT_READ, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x69000) = 0x7f2af848c000
mmap(0x7f2af84a9000, 12288, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x86000) = 0x7f2af84a9000

Confirmed dependency chain ccf -> librypto -> libsymcrypt (monolithic lib):

root [ /workspace/build ]# ldd /usr/lib/libsymcrypt.so.103
	statically linked

@maxtropets
Copy link
Collaborator Author

maxtropets commented Oct 28, 2024

Tried all other unit tests (crypto test patched with #6591)

 ./tests.sh -VV -L unit
...
The following tests FAILED:
	 11 - crypto_test (Failed)
	 13 - key_exchange_test (SEGFAULT)
	 18 - endorsements_test (Failed)
	 19 - historical_queries_test (SEGFAULT)
	 21 - snapshotter_test (SEGFAULT)
	 27 - channels_test (SEGFAULT)
	 28 - http_test (Failed)
	 37 - csr_test (Failed)

Split into smaller sub-issues except http_test, doesn't look openssl related, looking into it

UPD: Fixed in #6598

@maxtropets
Copy link
Collaborator Author

Got to the bottom of UVM endorsements test failure, filed a ticket (#6600)

So far, all the known issues are filed in sub-issues or solved.

Next steps

@maxtropets maxtropets changed the title Solve OpenSSL on Azure Linux Support CCF testing&running on Azure Linux Nov 15, 2024
@maxtropets maxtropets changed the title Support CCF testing&running on Azure Linux Support Azure Linux in CCF Nov 15, 2024
@maxtropets maxtropets changed the title Support Azure Linux in CCF Support running CCF on Azure Linux Nov 15, 2024
@maxtropets
Copy link
Collaborator Author

maxtropets commented Dec 20, 2024

Dumping to not lose, how to run the container + tests

docker run -ti --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v $(pwd):/workspace mcr.microsoft.com/azurelinux/base/core:3.0 /bin/bash

gpg --import /etc/pki/rpm-gpg/MICROSOFT-RPM-GPG-KEY && tdnf -y update && tdnf -y install ca-certificates git && tdnf -y install build-essential clang cmake ninja-build which && tdnf -y install openssl-devel libuv-devel perl && tdnf -y install libarrow-devel parquet-libs-devel && tdnf -y install lldb strace npm jq expect

git config --global --add safe.directory /workspace

CC=`which clang` CXX=`which clang++` cmake -GNinja -DCOMPILE_TARGET=virtual -DCMAKE_BUILD_TYPE=Debug -DLVI_MITIGATIONS=OFF -DUSE_LIBCXX=OFF ..

@maxtropets
Copy link
Collaborator Author

maxtropets commented Dec 27, 2024

Currently running standard e2e tests set (no perf, no ASAN/TSAN, etc) is blocked by

  • ./tests.sh -VV -R raft_scenario_test
    • Node n[2] detail leadership_state is not as expected: Follower != Leader on line 46 <br>
    • Node n[2] not at expected commit idx (13) on line 95 : 9 <br>
    • Looks like a proper raft failure, needs investigation
  • ./tests.sh -VV -R "programmability|modules_test"
    • Only JWK API part is broken, pem missmatch for certain keys, needs investigation
  • ./tests.sh -VV -R lts_compatibility
    • no dpkg, needs other way of installing CCF releases
    • possibly more problems can turn up, not clear at the moment

@maxtropets
Copy link
Collaborator Author

maxtropets commented Dec 30, 2024

./tests.sh -VV -R "programmability|modules_test"
Only JWK API part is broken, pem missmatch for certain keys, needs investigation

Checked it in-depth, key things to mention

  • this's random failure
  • the part of a test that fails is in a nutshell
    • create rsa key pair locally (on the python side)
    • call python.jwk to construct a JWK for the private key
    • call ccfcrypto.rsaPemToJwk and assert JWK is the same (always passes (!))
    • pass that JWK to ccfcrypto.rsaJwkToPem and verify the obtain PEM against the created one
  • fails, because they sometimes (!) don't match
  • even though they don't match, they seem to represent the same private key (at least this online checker accepts both PEMs: https://www.sslchecker.com/matcher)

As soon as both PEMs represent the same private key, it's to be figured out what metadata encoded makes the difference here

@maxtropets
Copy link
Collaborator Author

Example

Priv key converted to JWK and back to PEM

-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDg42t7WYRiQwhb
K26ScV2WZr689iGvNt944qlgonpiApFtPyRuZ9tTuk8Muxyq/rk9A+RsyxKgJoP5
a85WVeLg9b5cQ++FqsHAfWxTGKgOOUz8bGAGLDtWIfdoKpYI212hDJZ/GZl3BVRd
waTDUzMhEghLA8zNv+CSIIygtNa/wy1k7D5bQ2xcnP3wV8nPj9bWJRdFbyyLV6gc
cpKFQRWs8X+kYCsYjjztaNrlPluUYQ/8Uuzs78TNx+pCQT2vKXx+Ipwzpqk9GQMC
WkdE3w+xJHLYsJJzfn5grm0hTP0YQmwHI9/99EQ8LnVmRoPu69qM6kGQasTSN2Qp
to500dYhAgMBAAECggEAf28/i8FZLBlSFd+Ro7hL0RtdwFQ1GEWe8rB2TIUlln5g
DCj4qvt9JH/xpYQuJZN8Ql//Q8r7Pfc1V9RIM1It40491ajFhNgTPNGV3ayeJpk/
z9ZVv4m3AgLzYHqpVFGCR+2LJnDKLtC9UveVNv3hfj7qph98Iac2SXfaWILBIh4W
nE5SKBCdM95yzDxALYJj82FS9MekIkD3S6HHYXO1NXM5P79ILQ9SLqd5SRZhdPXq
/nN06jIZeUC4lV4cXNy8PYqOJTEC2NC9C0a7J++HePdO7+Vlt6ZmMo1fa6VvwuoJ
CNQZ9ZeTe2aIbdy03r8Kys0/aDqPofoxd+l+YTeMhQKBgQDyPzdLLigIAzl20B0+
IoiTXkhq3kvruYe7T5du/8Zf+1IsMWTzxD6BgA986BwuPFKLVg6Qr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KQu
G8vOAoY9HA5FtBHo6jXVY1xpb5970bBg1sv3D7c24XugyaiCBdIm3s4apknozP9K
OtmivWSBjPI6K3D+/QjfEDJ4Wxl6oflR02O+5/U+8rwrYaN506j7m5iiaFozdKVA
LKCCczubuG7xnqBf/CSQaJoPu/UkWZU8ZuLMMaYrAoGACZhCo4X6UB1iCoOq3NpM
JoMny3Pe4JkoR4Hj0iHVDqJ20zGlxfub3q0zW5DhbJe0oCq1ArOJKZKUy7d3POcv
aNqlhlyU4TQmpO+gFbOI0x63U2hk25sL9RkaEVApUxQ3d2uA461wSnPE/qgZ/fCY
CCm4sbaV7Bl8kqc7k/fbqmE=
-----END PRIVATE KEY-----

Public key

-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA4ONre1mEYkMIWytuknFd
lma+vPYhrzbfeOKpYKJ6YgKRbT8kbmfbU7pPDLscqv65PQPkbMsSoCaD+WvOVlXi
4PW+XEPvharBwH1sUxioDjlM/GxgBiw7ViH3aCqWCNtdoQyWfxmZdwVUXcGkw1Mz
IRIISwPMzb/gkiCMoLTWv8MtZOw+W0NsXJz98FfJz4/W1iUXRW8si1eoHHKShUEV
rPF/pGArGI487Wja5T5blGEP/FLs7O/EzcfqQkE9ryl8fiKcM6apPRkDAlpHRN8P
sSRy2LCSc35+YK5tIUz9GEJsByPf/fREPC51ZkaD7uvajOpBkGrE0jdkKbaOdNHW
IQIDAQAB
-----END PUBLIC KEY-----

@maxtropets
Copy link
Collaborator Author

maxtropets commented Dec 30, 2024

Tried ASN1 decoder, surely there's a difference in metadata, trying to figure out what exactly is it

Image

@maxtropets
Copy link
Collaborator Author

Converted the key obtained from CCF back to JWK with python.jwk, here's the the original pem->jwk on the left and new->jwk on the right

The d parameter doesn't match.

Image

@maxtropets
Copy link
Collaborator Author

maxtropets commented Dec 30, 2024

I've also tried a simple python test with sign/verify with both keys (different pems), worked out just well.

Learned some RSA docs, seems d is a defining parameter for a private key, so these are actually two different private keys. Verification with a public key works, because same n and e are applied.

Will dig up the implementation, but seems like either openssl version bump-up issue or a symcrypt problem.

@maxtropets
Copy link
Collaborator Author

Current summary

  • generating fresh key and getting it's PEM from python crypto
  • converting that PEM to JWK with both python.jwk and ccfcrypto - they match
  • converting JWK back to PEM* with python.jwk and ccfcrypto - they differ
  • converting PEM* back to JWK* with python.jwk and ccfcrypto - they match

Tried running local ccf crypto test as follows

  • generate new key
  • get its jwk and create a new key with it
  • match

That always passes, meaning there's something wrong with creating the key from parameters.

Open question - is it possible that PEM->JWK on one openssl version and then JWK->PEM on another openssl version aren't compatible?

@maxtropets
Copy link
Collaborator Author

Also, found this online jwk->pem->jwk thing: https://8gwifi.org/jwkconvertfunctions.jsp

JWK->PEM there matches the CCF version

@maxtropets
Copy link
Collaborator Author

@maxtropets
Copy link
Collaborator Author

Reproduced it in another way, getting a pem from a failed test, then unit-testing as follows

  const auto pem =
    "-----BEGIN PRIVATE KEY-----\n"
    "MIIEvgIBADANBgkqhkiG9w0BAQEFAASCBKgwggSkAgEAAoIBAQDMm8GpgeYyat7+\n"
    "K4FgIIuftNj2f8asetGaqcG3idkd11DMEXRs6CEpsiUEIN7JEOsqyhL7lSgblfia\n"
    "HFV6Cius5kJObINgDicDpITRjAn1XHOSGZiotMXiOe565/Zzo1gxg9Bu0TroG0H1\n"
    "pt4f9ekrhv7ZkVP6hxSCQ/j/dJyHS7xXvV5LIeERJTYssuyr0749InE1Sss/p77Y\n"
    "2rPJR8GF4S9JCTJEcE2NMNa8WxO4g6Gg+uS+P3TPRUlc9H2lvLf31QDbtGKhRG1F\n"
    "wYqHYRuk8EcB6bH6xiNQ0a5pwNVcw2bIGbwfJeQO9dnDjISWIt8sZQr7kLzB2OeP\n"
    "+BSdRA2hAgMBAAECggEABvQsNXSYEZKW7ZB7nya8AruEvCvvi/ZzSoxbwb8fmpIH\n"
    "dEgLlZVLZegLYK6Ko869ZKuQJZjAz4nd9G7ja3hjr5v2bkU7LyKL/5B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AnBjgIlnOpfKXkgQdYsNyj2n3hGRPoh42Or9gL8PmEupDa2V3SiuKLCevFH\n"
    "DZT1zBqh3f+3q5Tko7nYL13+uWlwz4COa551LYeTjKDqSEq40eBQ7HFTWOW0+zqF\n"
    "frD1OBFK+2NytBQFs+EvbWUC\n"
    "-----END PRIVATE KEY-----\n";

  const auto key = ccf::crypto::make_rsa_key_pair(ccf::crypto::Pem(pem));

  const auto jwk = key->private_key_jwk_rsa();
  std::cout << "JWK: d old=" << jwk.d << std::endl;

  const auto key2 = ccf::crypto::make_rsa_key_pair(jwk);
  const auto jwk2 = key2->private_key_jwk_rsa();
  std::cout << "JWK: d new=" << jwk2.d << std::endl;

  REQUIRE(jwk.d == jwk2.d);

This passes on our current Ubuntu 20.04 with openssl 1.1.1, but fails on Mariner with openssl 3.3

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

No branches or pull requests

2 participants