|
15 | 15 | import java.security.cert.Certificate; |
16 | 16 | import java.util.Arrays; |
17 | 17 | import java.io.IOException; |
| 18 | +import java.io.InputStreamReader; |
| 19 | + |
18 | 20 | import org.bouncycastle.openssl.*; |
19 | 21 | import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter; |
| 22 | +import org.bouncycastle.util.io.pem.PemReader; |
20 | 23 | import org.bouncycastle.asn1.pkcs.PrivateKeyInfo; |
21 | 24 | import org.java_websocket.client.WebSocketClient; |
22 | 25 | import org.java_websocket.framing.Framedata; |
|
46 | 49 | import com.peersafe.base.client.transport.TransportEventHandler; |
47 | 50 | import com.peersafe.base.client.transport.WebSocketTransport; |
48 | 51 | import com.peersafe.base.crypto.X509CryptoSuite; |
| 52 | +import com.peersafe.chainsql.util.Util; |
49 | 53 |
|
50 | 54 | class WS extends WebSocketClient { |
51 | 55 |
|
@@ -214,11 +218,26 @@ public void connectSSL(URI uri, String[] trustCAsPath, String sslKeyPath, String |
214 | 218 | throw new RuntimeException("must call setEventHandler() before connect(...)"); |
215 | 219 | } |
216 | 220 |
|
217 | | - String certSigAlg = ((X509Certificate)readCert(trustCAsPath[0])).getSigAlgName(); |
218 | | - if(certSigAlg.equals("SM3withSM2")) |
219 | | - { |
220 | | - isGM = true; |
| 221 | + if(trustCAsPath.length != 0) { |
| 222 | + String certSigAlg = ((X509Certificate)readCert(trustCAsPath[0])).getSigAlgName(); |
| 223 | + String certPubKeyAlg = "0608"; |
| 224 | + if(sslCertPath.length() != 0) { |
| 225 | + PemReader pemReader = new PemReader(new InputStreamReader(new FileInputStream(sslCertPath))); |
| 226 | + byte[] subPubkeyInfo = org.bouncycastle.asn1.x509.Certificate.getInstance(pemReader.readPemObject() |
| 227 | + .getContent()).getSubjectPublicKeyInfo().getEncoded(); |
| 228 | + pemReader.close(); |
| 229 | + String subPubkeyAlg = Util.bytesToHex(subPubkeyInfo); |
| 230 | + certPubKeyAlg = subPubkeyAlg.length() > 45 ? subPubkeyAlg.substring(26,46) : subPubkeyAlg; |
| 231 | + } |
| 232 | + if(certSigAlg.equals("SM3withSM2") || certPubKeyAlg.equals("06082A811CCF5501822D")) |
| 233 | + { |
| 234 | + isGM = true; |
| 235 | + } |
| 236 | + } |
| 237 | + else { |
| 238 | + throw new RuntimeException("Must specify at least a trustCA"); |
221 | 239 | } |
| 240 | + |
222 | 241 |
|
223 | 242 | KeyStore tks; |
224 | 243 | tks = getKeyStore(trustCAsPath, null); |
|
0 commit comments