Sender(String hex) { value = ArrayConverter.hexStringToByteArray(hex); }
/** * Returns the next word from the inputstream. If no more words are in the * in InputStream null is returned. * * @return The next word from the inputstream. If no more words are in the * in InputStream null is returned. */ @Override public byte[] getGuess() { try { String line = bufferedReader.readLine(); if (line == null) { return null; } return ArrayConverter.hexStringToByteArray(line); } catch (IOException ex) { return null; } } }
@Override public Certificate unmarshal(String v) throws Exception { Certificate cert = Certificate.parse(new ByteArrayInputStream(ArrayConverter.hexStringToByteArray(v.replaceAll( "\\s+", "")))); return cert; }
@Override public byte[] convert(String value) { try { return ArrayConverter.hexStringToByteArray(value); } catch (IllegalArgumentException ex) { throw new ParameterException("Could not parse " + value + ". Not a hex String"); } }
mac.update(info); if (Integer.toHexString(i).length() % 2 != 0) { mac.update(ArrayConverter.hexStringToByteArray("0" + Integer.toHexString(i))); } else { mac.update(ArrayConverter.hexStringToByteArray(Integer.toHexString(i)));
private void prepareCipherKind(SSL2ClientMasterKeyMessage message) { // by default we currently just try export RC4 message.setCipherKind(ArrayConverter.hexStringToByteArray("020080")); LOGGER.debug("CipherKind: " + ArrayConverter.bytesToHexString(message.getCipherKind().getValue())); }
@Override public X509CertificateObject unmarshal(String v) throws Exception { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); Collection<? extends java.security.cert.Certificate> certs = certFactory .generateCertificates(new ByteArrayInputStream(ArrayConverter.hexStringToByteArray(v.replaceAll("\\s+", "")))); java.security.cert.Certificate sunCert = (java.security.cert.Certificate) certs.toArray()[0]; byte[] certBytes = sunCert.getEncoded(); ASN1Primitive asn1Cert = TlsUtils.readDERObject(certBytes); org.bouncycastle.asn1.x509.Certificate cert = org.bouncycastle.asn1.x509.Certificate.getInstance(asn1Cert); org.bouncycastle.asn1.x509.Certificate[] certs2 = new org.bouncycastle.asn1.x509.Certificate[1]; certs2[0] = cert; org.bouncycastle.crypto.tls.Certificate tlsCerts = new org.bouncycastle.crypto.tls.Certificate(certs2); X509CertificateObject x509CertObject = new X509CertificateObject(tlsCerts.getCertificateAt(0)); return x509CertObject; }
public BigInteger calculateX(byte[] salt, byte[] identity, byte[] password) { byte[] hashInput1 = ArrayConverter.concatenate(identity, ArrayConverter.hexStringToByteArray("3A"), password); LOGGER.debug("HashInput for hashInput1: " + ArrayConverter.bytesToHexString(hashInput1)); byte[] hashOutput1 = SHAsum(hashInput1); LOGGER.debug("Hashvalue for hashInput1: " + ArrayConverter.bytesToHexString(hashOutput1)); byte[] hashInput2 = ArrayConverter.concatenate(salt, hashOutput1); LOGGER.debug("HashInput for hashInput2: " + ArrayConverter.bytesToHexString(hashInput2)); byte[] hashOutput2 = SHAsum(hashInput2); LOGGER.debug("Hashvalue for hashInput2: " + ArrayConverter.bytesToHexString(hashOutput2)); return new BigInteger(1, hashOutput2); }
public BigInteger calculateX(byte[] salt, byte[] identity, byte[] password) { byte[] hashInput1 = ArrayConverter.concatenate(identity, ArrayConverter.hexStringToByteArray("3A"), password); LOGGER.debug("HashInput for hashInput1: " + ArrayConverter.bytesToHexString(hashInput1)); byte[] hashOutput1 = SHAsum(hashInput1); LOGGER.debug("Hashvalue for hashInput1: " + ArrayConverter.bytesToHexString(hashOutput1)); byte[] hashInput2 = ArrayConverter.concatenate(salt, hashOutput1); LOGGER.debug("HashInput for hashInput2: " + ArrayConverter.bytesToHexString(hashInput2)); byte[] hashOutput2 = SHAsum(hashInput2); LOGGER.debug("Hashvalue for hashInput2: " + ArrayConverter.bytesToHexString(hashOutput2)); return new BigInteger(1, hashOutput2); }
private void prepareCipherSuites(SSL2ClientHelloMessage message) { message.setCipherSuites(ArrayConverter.hexStringToByteArray("0700c0060040050080040080030080020080010080080080")); LOGGER.debug("CipherSuites: " + ArrayConverter.bytesToHexString(message.getCipherSuites().getValue())); }
defaultClientKeyShareEntries = new LinkedList<>(); defaultClientKeyShareEntries.add(new KeyShareStoreEntry(NamedGroup.ECDH_X25519, ArrayConverter .hexStringToByteArray("2A981DB6CDD02A06C1763102C9E741365AC4E6F72B3176A6BD6A3523D3EC0F4C"))); defaultServerKeyShareEntry = new KeyShareStoreEntry(NamedGroup.ECDH_X25519, ArrayConverter.hexStringToByteArray("2A981DB6CDD02A06C1763102C9E741365AC4E6F72B3176A6BD6A3523D3EC0F4C")); pskKeyExchangeModes = new LinkedList<>(); pskKeyExchangeModes.add(PskKeyExchangeMode.PSK_KE); .parse(new ByteArrayInputStream( ArrayConverter .hexStringToByteArray("0003970003943082039030820278A003020102020900A650C00794049FCD300D06092A864886F70D01010B0500305C310B30090603550406130241553113301106035504080C0A536F6D652D53746174653121301F060355040A0C18496E7465726E6574205769646769747320507479204C74643115301306035504030C0C544C532D41747461636B65723020170D3137303731333132353331385A180F32313137303631393132353331385A305C310B30090603550406130241553113301106035504080C0A536F6D652D53746174653121301F060355040A0C18496E7465726E6574205769646769747320507479204C74643115301306035504030C0C544C532D41747461636B657230820122300D06092A864886F70D01010105000382010F003082010A0282010100C8820D6C3CE84C8430F6835ABFC7D7A912E1664F44578751F376501A8C68476C3072D919C5D39BD0DBE080E71DB83BD4AB2F2F9BDE3DFFB0080F510A5F6929C196551F2B3C369BE051054C877573195558FD282035934DC86EDAB8D4B1B7F555E5B2FEE7275384A756EF86CB86793B5D1333F0973203CB96966766E655CD2CCCAE1940E4494B8E9FB5279593B75AFD0B378243E51A88F6EB88DEF522A8CD5C6C082286A04269A2879760FCBA45005D7F2672DD228809D47274F0FE0EA5531C2BD95366C05BF69EDC0F3C3189866EDCA0C57ADCCA93250AE78D9EACA0393A95FF9952FC47FB7679DD3803E6A7A6FA771861E3D99E4B551A4084668B111B7EEF7D0203010001A3533051301D0603551D0E04160414E7A92FE5543AEE2FF7592F800AC6E66541E3268B301F0603551D23041830168014E7A92FE5543AEE2FF7592F800AC6E66541E3268B300F0603551D130101FF040530030101FF300D06092A864886F70D01010B050003820101000D5C11E28CF19D1BC17E4FF543695168570AA7DB85B3ECB85405392A0EDAFE4F097EE4685B7285E3D9B869D23257161CA65E20B5E6A585D33DA5CD653AF81243318132C9F64A476EC08BA80486B3E439F765635A7EA8A969B3ABD8650036D74C5FC4A04589E9AC8DC3BE2708743A6CFE3B451E3740F735F156D6DC7FFC8A2C852CD4E397B942461C2FCA884C7AFB7EBEF7918D6AAEF1F0D257E959754C4665779FA0E3253EF2BEDBBD5BE5DA600A0A68E51D2D1C125C4E198669A6BC715E8F3884E9C3EFF39D40838ADA4B1F38313F6286AA395DC6DEA9DAF49396CF12EC47EFA7A0D3882F8B84D9AEEFFB252C6B81A566609605FBFD3F0D17E5B12401492A1A"))); } catch (IOException ex) { throw new ConfigurationException("Could not create default config");
byte[] pms = ArrayConverter.hexStringToByteArray(config.getEncryptedPremasterSecret()); if ((pms.length * 8) != publicKey.getModulus().bitLength()) { throw new ConfigurationException("The length of the encrypted premaster secret you have "
byte[] earlySecret = HKDFunction.extract(hkdfAlgortihm, new byte[0], psk); byte[] binderKey = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), earlySecret, HKDFunction.BINDER_KEY_RES, ArrayConverter.hexStringToByteArray("")); byte[] binderFinKey = HKDFunction.expandLabel(hkdfAlgortihm, binderKey, HKDFunction.FINISHED, new byte[0], mac.getMacLength());
private byte[] createSignature() throws CryptoException { byte[] toBeSigned = chooser.getContext().getDigest().getRawBytes(); if (chooser.getSelectedProtocolVersion().isTLS13()) { if (chooser.getConnectionEndType() == ConnectionEndType.CLIENT) { toBeSigned = ArrayConverter .concatenate( ArrayConverter .hexStringToByteArray("20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020"), CertificateVerifiyConstants.CLIENT_CERTIFICATE_VERIFY.getBytes(), new byte[] { (byte) 0x00 }, chooser.getContext().getDigest() .digest(chooser.getSelectedProtocolVersion(), chooser.getSelectedCipherSuite())); } else { toBeSigned = ArrayConverter .concatenate( ArrayConverter .hexStringToByteArray("20202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020202020"), CertificateVerifiyConstants.SERVER_CERTIFICATE_VERIFY.getBytes(), new byte[] { (byte) 0x00 }, chooser.getContext().getDigest() .digest(chooser.getSelectedProtocolVersion(), chooser.getSelectedCipherSuite())); } } else if (chooser.getSelectedProtocolVersion().isSSL()) { final byte[] handshakeMessageContent = chooser.getContext().getDigest().getRawBytes(); final byte[] masterSecret = chooser.getMasterSecret(); return SSLUtils.calculateSSLCertificateVerifySignature(handshakeMessageContent, masterSecret); } algorithm = chooser.getSelectedSigHashAlgorithm(); return SignatureCalculator.generateSignature(algorithm, chooser, toBeSigned); }
private void adjustApplicationTrafficSecrets() { HKDFAlgorithm hkdfAlgortihm = AlgorithmResolver.getHKDFAlgorithm(tlsContext.getChooser() .getSelectedCipherSuite()); DigestAlgorithm digestAlgo = AlgorithmResolver.getDigestAlgorithm(tlsContext.getChooser() .getSelectedProtocolVersion(), tlsContext.getChooser().getSelectedCipherSuite()); try { int macLength = Mac.getInstance(hkdfAlgortihm.getMacAlgorithm().getJavaName()).getMacLength(); byte[] saltMasterSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), tlsContext .getChooser().getHandshakeSecret(), HKDFunction.DERIVED, ArrayConverter.hexStringToByteArray("")); byte[] masterSecret = HKDFunction.extract(hkdfAlgortihm, saltMasterSecret, new byte[macLength]); byte[] clientApplicationTrafficSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), masterSecret, HKDFunction.CLIENT_APPLICATION_TRAFFIC_SECRET, tlsContext.getDigest().getRawBytes()); tlsContext.setClientApplicationTrafficSecret(clientApplicationTrafficSecret); LOGGER.debug("Set clientApplicationTrafficSecret in Context to " + ArrayConverter.bytesToHexString(clientApplicationTrafficSecret)); byte[] serverApplicationTrafficSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), masterSecret, HKDFunction.SERVER_APPLICATION_TRAFFIC_SECRET, tlsContext.getDigest().getRawBytes()); tlsContext.setServerApplicationTrafficSecret(serverApplicationTrafficSecret); LOGGER.debug("Set serverApplicationTrafficSecret in Context to " + ArrayConverter.bytesToHexString(serverApplicationTrafficSecret)); tlsContext.setMasterSecret(masterSecret); LOGGER.debug("Set masterSecret in Context to " + ArrayConverter.bytesToHexString(masterSecret)); } catch (NoSuchAlgorithmException | CryptoException ex) { throw new AdjustmentException(ex); } }
byte[] earlySecret = HKDFunction.extract(hkdfAlgortihm, new byte[0], psk); byte[] saltHandshakeSecret = HKDFunction.deriveSecret(hkdfAlgortihm, digestAlgo.getJavaName(), earlySecret, HKDFunction.DERIVED, ArrayConverter.hexStringToByteArray("")); byte[] sharedSecret = new byte[macLength]; if (tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT) {