Skip to content

Commit

Permalink
TKSS-808: Remove SSLUtils::getECKeyPairGenerator
Browse files Browse the repository at this point in the history
  • Loading branch information
johnshajiang committed Jul 3, 2024
1 parent 18027dc commit 3a01fec
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 22 deletions.
13 changes: 1 addition & 12 deletions kona-ssl/src/main/java/com/tencent/kona/ssl/SSLUtils.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2022, 2023, THL A29 Limited, a Tencent company. All rights reserved.
* Copyright (C) 2022, 2024, THL A29 Limited, a Tencent company. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify
Expand All @@ -20,10 +20,6 @@

package com.tencent.kona.ssl;

import com.tencent.kona.crypto.CryptoInsts;

import java.security.KeyPairGenerator;
import java.security.NoSuchAlgorithmException;
import java.util.Locale;

/**
Expand All @@ -45,11 +41,4 @@ public static void setPropCertListFormat(String format) {
}

/* ***** System properties end ***** */

public static KeyPairGenerator getECKeyPairGenerator(String namedGroup)
throws NoSuchAlgorithmException {
String algorithm = "curvesm2".equalsIgnoreCase(namedGroup)
? "SM2" : "EC";
return CryptoInsts.getKeyPairGenerator(algorithm);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
import javax.net.ssl.SSLHandshakeException;

import com.tencent.kona.crypto.CryptoInsts;
import com.tencent.kona.ssl.SSLUtils;
import com.tencent.kona.sun.security.util.ECUtil;
import com.tencent.kona.sun.security.ssl.NamedGroup.NamedGroupSpec;
import com.tencent.kona.sun.security.ssl.X509Authentication.X509Credentials;
Expand Down Expand Up @@ -114,8 +113,7 @@ static final class ECDHEPossession implements NamedGroupPossession {

ECDHEPossession(NamedGroup namedGroup, SecureRandom random) {
try {
KeyPairGenerator kpg = SSLUtils.getECKeyPairGenerator(
namedGroup.name);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
kpg.initialize(namedGroup.keAlgParamSpec, random);
KeyPair kp = kpg.generateKeyPair();
privateKey = kp.getPrivate();
Expand All @@ -131,8 +129,7 @@ static final class ECDHEPossession implements NamedGroupPossession {
ECDHEPossession(ECDHECredentials credentials, SecureRandom random) {
ECParameterSpec params = credentials.popPublicKey.getParams();
try {
KeyPairGenerator kpg = SSLUtils.getECKeyPairGenerator(
credentials.namedGroup.name);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
kpg.initialize(params, random);
KeyPair kp = kpg.generateKeyPair();
privateKey = kp.getPrivate();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

import com.tencent.kona.crypto.CryptoInsts;
import com.tencent.kona.crypto.spec.SM2KeyAgreementParamSpec;
import com.tencent.kona.ssl.SSLUtils;
import com.tencent.kona.sun.security.ssl.TLCPAuthentication.TLCPPossession;
import com.tencent.kona.sun.security.util.ECUtil;

Expand Down Expand Up @@ -116,8 +115,7 @@ static final class SM2EPossession implements NamedGroupPossession {
SM2EPossession(TLCPPossession tlcpPossession,
NamedGroup namedGroup, SecureRandom random) {
try {
KeyPairGenerator kpg
= SSLUtils.getECKeyPairGenerator(namedGroup.name);
KeyPairGenerator kpg = KeyPairGenerator.getInstance("EC");
kpg.initialize(namedGroup.keAlgParamSpec, random);
KeyPair kp = kpg.generateKeyPair();
ephemeralPrivateKey = (ECPrivateKey) kp.getPrivate();
Expand All @@ -133,10 +131,9 @@ static final class SM2EPossession implements NamedGroupPossession {

@Override
public byte[] encode() {
byte[] encodedPoint = ECUtil.encodePoint(
return ECUtil.encodePoint(
ephemeralPublicKey.getW(),
ephemeralPublicKey.getParams().getCurve());
return encodedPoint;
}

// called by ClientHandshaker with either the server's static or
Expand Down

0 comments on commit 3a01fec

Please sign in to comment.