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

Remove secp256k as unsupported by symcrypt on Mariner #6602

Merged
merged 1 commit into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

### Removed

- Remove SECP256K1 support as a part of the migration to Azure Linux (#6592).

## [6.0.0-dev3]

[6.0.0-dev3]: https://github.com/microsoft/CCF/releases/tag/6.0.0-dev3
Expand Down
5 changes: 0 additions & 5 deletions include/ccf/crypto/curve.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ namespace ccf::crypto
SECP384R1,
/// The SECP256R1 curve
SECP256R1,
/// The SECP256K1 curve
SECP256K1,
/// The CURVE25519 curve
CURVE25519,
X25519
Expand All @@ -34,7 +32,6 @@ namespace ccf::crypto
{{CurveID::NONE, "None"},
{CurveID::SECP384R1, "Secp384R1"},
{CurveID::SECP256R1, "Secp256R1"},
{CurveID::SECP256K1, "Secp256K1"},
{CurveID::CURVE25519, "Curve25519"},
{CurveID::X25519, "X25519"}});

Expand All @@ -50,8 +47,6 @@ namespace ccf::crypto
return MDType::SHA384;
case CurveID::SECP256R1:
return MDType::SHA256;
case CurveID::SECP256K1:
return MDType::SHA256;
default:
{
throw std::logic_error(fmt::format("Unhandled CurveID: {}", ec));
Expand Down
12 changes: 2 additions & 10 deletions include/ccf/crypto/jwk.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,12 @@ namespace ccf::crypto
enum class JsonWebKeyECCurve
{
P256 = 0,
P256K1 = 1,
P384 = 2,
P521 = 3
P384 = 1,
P521 = 2
achamayou marked this conversation as resolved.
Show resolved Hide resolved
};
DECLARE_JSON_ENUM(
JsonWebKeyECCurve,
{{JsonWebKeyECCurve::P256, "P-256"},
{JsonWebKeyECCurve::P256K1,
"secp256k1"}, // As per
// https://www.rfc-editor.org/rfc/rfc8812#name-jose-and-cose-secp256k1-cur
{JsonWebKeyECCurve::P384, "P-384"},
{JsonWebKeyECCurve::P521, "P-521"}});

Expand All @@ -59,8 +55,6 @@ namespace ccf::crypto
return JsonWebKeyECCurve::P384;
case CurveID::SECP256R1:
return JsonWebKeyECCurve::P256;
case CurveID::SECP256K1:
return JsonWebKeyECCurve::P256K1;
default:
throw std::logic_error(fmt::format("Unknown curve {}", curve_id));
}
Expand All @@ -74,8 +68,6 @@ namespace ccf::crypto
return CurveID::SECP384R1;
case JsonWebKeyECCurve::P256:
return CurveID::SECP256R1;
case JsonWebKeyECCurve::P256K1:
return CurveID::SECP256K1;
default:
throw std::logic_error(fmt::format("Unknown JWK curve {}", jwk_curve));
}
Expand Down
2 changes: 1 addition & 1 deletion js/ccf-app/src/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ export interface CCFCrypto {
/**
* Generate an ECDSA key pair.
*
* @param curve The name of the curve, one of "secp256r1", "secp256k1", "secp384r1".
* @param curve The name of the curve, one of "secp256r1", "secp384r1".
*/
generateEcdsaKeyPair(curve: string): CryptoKeyPair;

Expand Down
9 changes: 1 addition & 8 deletions js/ccf-app/test/polyfill.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,6 @@ describe("polyfill", function () {
assert.isTrue(pair.privateKey.startsWith("-----BEGIN PRIVATE KEY-----"));
});
});
describe("generateEcdsaKeyPair/secp256k1", function () {
it("generates a random ECDSA P256K1 key pair", function () {
const pair = ccf.crypto.generateEcdsaKeyPair("secp256k1");
assert.isTrue(pair.publicKey.startsWith("-----BEGIN PUBLIC KEY-----"));
assert.isTrue(pair.privateKey.startsWith("-----BEGIN PRIVATE KEY-----"));
});
});
describe("generateEcdsaKeyPair/secp384r1", function () {
it("generates a random ECDSA P384R1 key pair", function () {
const pair = ccf.crypto.generateEcdsaKeyPair("secp384r1");
Expand Down Expand Up @@ -586,7 +579,7 @@ describe("polyfill", function () {
describe("pemToJwk and jwkToPem", function () {
it("EC", function () {
const my_kid = "my_kid";
const curves = ["secp256r1", "secp256k1", "secp384r1"];
const curves = ["secp256r1", "secp384r1"];
for (const curve of curves) {
const pair = ccf.crypto.generateEcdsaKeyPair(curve);
{
Expand Down
8 changes: 0 additions & 8 deletions src/crypto/openssl/public_key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,6 @@ namespace ccf::crypto
return CurveID::SECP384R1;
case NID_X9_62_prime256v1:
return CurveID::SECP256R1;
case NID_secp256k1:
return CurveID::SECP256K1;
default:
throw std::runtime_error(fmt::format("Unknown OpenSSL curve {}", nid));
}
Expand All @@ -163,10 +161,6 @@ namespace ccf::crypto
{
return NID_X9_62_prime256v1;
}
else if (gname == SN_secp256k1)
{
return NID_secp256k1;
}
else
{
throw std::runtime_error(fmt::format("Unknown OpenSSL group {}", gname));
Expand All @@ -187,8 +181,6 @@ namespace ccf::crypto
return NID_secp384r1;
case CurveID::SECP256R1:
return NID_X9_62_prime256v1;
case CurveID::SECP256K1:
return NID_secp256k1;
default:
throw std::logic_error(
fmt::format("unsupported OpenSSL CurveID {}", gid));
Expand Down
41 changes: 0 additions & 41 deletions src/crypto/test/bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,9 +154,6 @@ namespace CREATE_KEYPAIRS
auto create_256r1 = benchmark_create<KeyPair_OpenSSL, CurveID::SECP256R1>;
PICOBENCH(create_256r1).iterations({1000}).samples(10);

auto create_256k1 = benchmark_create<KeyPair_OpenSSL, CurveID::SECP256K1>;
PICOBENCH(create_256k1).iterations({1000}).samples(10);

auto create_384r1 = benchmark_create<KeyPair_OpenSSL, CurveID::SECP384R1>;
PICOBENCH(create_384r1).iterations({1000}).samples(10);
}
Expand Down Expand Up @@ -193,22 +190,6 @@ namespace SIGN_SECP256R1
PICOBENCH(sign_256r1_ossl_100k).PICO_SUFFIX(CurveID::SECP256R1);
}

PICOBENCH_SUITE("sign secp256k1");
namespace SIGN_SECP256K1
{
auto sign_256k1_ossl_1byte =
benchmark_sign<KeyPair_OpenSSL, CurveID::SECP256K1, 1>;
PICOBENCH(sign_256k1_ossl_1byte).PICO_SUFFIX(CurveID::SECP256K1);

auto sign_256k1_ossl_1k =
benchmark_sign<KeyPair_OpenSSL, CurveID::SECP256K1, 1024>;
PICOBENCH(sign_256k1_ossl_1k).PICO_SUFFIX(CurveID::SECP256K1);

auto sign_256k1_ossl_100k =
benchmark_sign<KeyPair_OpenSSL, CurveID::SECP256K1, 102400>;
PICOBENCH(sign_256k1_ossl_100k).PICO_SUFFIX(CurveID::SECP256K1);
}

PICOBENCH_SUITE("verify secp384r1");
namespace SECP384R1
{
Expand Down Expand Up @@ -253,28 +234,6 @@ namespace SECP256R1
PICOBENCH(verify_256r1_ossl_100k).PICO_SUFFIX(CurveID::SECP256R1);
}

PICOBENCH_SUITE("verify secp256k1");
namespace SECP256K1
{
auto verify_256k1_ossl_1byte =
benchmark_verify<KeyPair_OpenSSL, PublicKey_OpenSSL, CurveID::SECP256K1, 1>;
PICOBENCH(verify_256k1_ossl_1byte).PICO_SUFFIX(CurveID::SECP256K1);

auto verify_256k1_ossl_1k = benchmark_verify<
KeyPair_OpenSSL,
PublicKey_OpenSSL,
CurveID::SECP256K1,
1024>;
PICOBENCH(verify_256k1_ossl_1k).PICO_SUFFIX(CurveID::SECP256K1);

auto verify_256k1_ossl_100k = benchmark_verify<
KeyPair_OpenSSL,
PublicKey_OpenSSL,
CurveID::SECP256K1,
102400>;
PICOBENCH(verify_256k1_ossl_100k).PICO_SUFFIX(CurveID::SECP256K1);
}

PICOBENCH_SUITE("sign RSA-2048");
namespace SIGN_RSA2048
{
Expand Down
6 changes: 3 additions & 3 deletions src/crypto/test/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ void corrupt(T& buf)
}

static constexpr CurveID supported_curves[] = {
CurveID::SECP384R1, CurveID::SECP256R1, CurveID::SECP256K1};
CurveID::SECP384R1, CurveID::SECP256R1};

static constexpr char const* labels[] = {"secp384r1", "secp256r1", "secp256k1"};
static constexpr char const* labels[] = {"secp384r1", "secp256r1"};

ccf::crypto::Pem generate_self_signed_cert(
const KeyPairPtr& kp, const std::string& name)
Expand Down Expand Up @@ -1045,7 +1045,7 @@ TEST_CASE("PEM to JWK and back")

INFO("EC");
{
auto curves = {CurveID::SECP384R1, CurveID::SECP256R1, CurveID::SECP256K1};
auto curves = {CurveID::SECP384R1, CurveID::SECP256R1};

for (auto const& curve : curves)
{
Expand Down
7 changes: 1 addition & 6 deletions src/js/extensions/ccf/crypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,19 +132,14 @@ namespace ccf::js::extensions
{
cid = ccf::crypto::CurveID::SECP256R1;
}
else if (curve == "secp256k1")
{
cid = ccf::crypto::CurveID::SECP256K1;
}
else if (curve == "secp384r1")
{
cid = ccf::crypto::CurveID::SECP384R1;
}
else
{
return JS_ThrowRangeError(
ctx,
"Unsupported curve id, supported: secp256r1, secp256k1, secp384r1");
ctx, "Unsupported curve id, supported: secp256r1, secp384r1");
}

try
Expand Down
12 changes: 3 additions & 9 deletions tests/npm_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def generate_and_verify_jwk(client):
assert r.status_code != http.HTTPStatus.OK

# Elliptic curve
curves = [ec.SECP256R1, ec.SECP256K1, ec.SECP384R1]
curves = [ec.SECP256R1, ec.SECP384R1]
for curve in curves:
priv_pem, pub_pem = infra.crypto.generate_ec_keypair(curve)
# Private
Expand Down Expand Up @@ -305,12 +305,6 @@ def test_npm_app(network, args):
r.body.json()["privateKey"], r.body.json()["publicKey"]
)

r = c.post("/app/generateEcdsaKeyPair", {"curve": "secp256k1"})
assert r.status_code == http.HTTPStatus.OK, r.status_code
assert infra.crypto.check_key_pair_pem(
r.body.json()["privateKey"], r.body.json()["publicKey"]
)

r = c.post("/app/generateEcdsaKeyPair", {"curve": "secp384r1"})
assert r.status_code == http.HTTPStatus.OK, r.status_code
assert infra.crypto.check_key_pair_pem(
Expand Down Expand Up @@ -475,7 +469,7 @@ def test_npm_app(network, args):
pass

# Test ECDSA signing + verification
curves = [ec.SECP256R1, ec.SECP256K1, ec.SECP384R1]
curves = [ec.SECP256R1, ec.SECP384R1]
for curve in curves:
key_priv_pem, key_pub_pem = infra.crypto.generate_ec_keypair(curve)
algorithm = {"name": "ECDSA", "hash": "SHA-256"}
Expand Down Expand Up @@ -577,7 +571,7 @@ def test_npm_app(network, args):
assert r.status_code == http.HTTPStatus.OK, r.status_code
assert r.body.json() is False, r.body

curves = [ec.SECP256R1, ec.SECP256K1, ec.SECP384R1]
curves = [ec.SECP256R1, ec.SECP384R1]
for curve in curves:
key_priv_pem, key_pub_pem = infra.crypto.generate_ec_keypair(curve)
algorithm = {"name": "ECDSA", "hash": "SHA-256"}
Expand Down