@Override public TransformationSpec[] getTransformationSpecWithStrength(String provider, String mechanism, int strength, String... tokens) throws IllegalArgumentException { Assert.checkNotNullParam("tokens", tokens); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } ArrayList<TransformationSpec> tf = new ArrayList<TransformationSpec>(ts.length); for (TransformationSpec t : ts) { for (String token : tokens) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()) && (strength <= t.getStrength()))) { tf.add(t); } } } return tf.toArray(new TransformationSpec[tf.size()]); }
public DefaultTransformationMapper() { transformations.put("DIGEST-MD5", new TransformationSpec[] { // TODO: once digest-md5 PR will be merged change this to // JBOSS_DIGEST_MD5 new TransformationSpec("3des", "DESede/CBC/NoPadding", NO_KEY, HIGH_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4", "RC4", 128, HIGH_STRENGTH, "SunJCA"), new TransformationSpec("des", "DES/CBC/NoPadding", NO_KEY, MEDIUM_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4-56", "RC4", 56, MEDIUM_STRENGTH, "SunJCA"), new TransformationSpec("rc4-40", "RC4", 40, LOW_STRENGTH, "SunJCA") }); // sort all transformation arrays descending by strength for (String mech : transformations.keySet()) { Arrays.sort(transformations.get(mech), (o1, o2) -> { if (o1.getStrength() < o2.getStrength()) { return 1; } else if (o1.getStrength() > o2.getStrength()) { return -1; } else { return 0; } }); } }
throw saslDigest.mechUnknownCipher(cipher).toSaslException(); ciph = Cipher.getInstance(transformationSpec.getTransformation()); int slash = ciph.getAlgorithm().indexOf('/'); String alg = (slash > -1 ? ciph.getAlgorithm().substring(0, slash) : ciph.getAlgorithm());
@Override public TransformationSpec getTransformationSpec(String provider, String mechanism, String token) throws IllegalArgumentException { Assert.checkNotNullParam("token", token); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } for (TransformationSpec t : ts) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()))) { return t; } } return null; }
/** * Get supported ciphers as comma separated list of cipher-opts by Digest MD5 spec. * * @return comma separated list of ciphers */ static String getSupportedCiphers(String[] demandedCiphers) { TransformationMapper trans = new DefaultTransformationMapper(); if (demandedCiphers == null) { demandedCiphers = CIPHER_OPTS; } StringBuilder ciphers = new StringBuilder(); for (TransformationSpec ts: trans.getTransformationSpecByStrength(SaslMechanismInformation.Names.DIGEST_MD5, demandedCiphers)) { if (ciphers.length() > 0) { ciphers.append(DELIMITER); } ciphers.append(ts.getToken()); } return ciphers.toString(); }
@Override public TransformationSpec[] getTransformationSpecByStrength(String provider, String mechanism, String... tokens) throws IllegalArgumentException { Assert.checkNotNullParam("tokens", tokens); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } ArrayList<TransformationSpec> tf = new ArrayList<TransformationSpec>(ts.length); for (TransformationSpec t : ts) { for (String token : tokens) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()))) { tf.add(t); } } } return tf.toArray(new TransformationSpec[tf.size()]); }
private String selectCipher(String ciphersFromServer) throws SaslException { if (ciphersFromServer == null) { throw saslDigest.mechNoCiphersOfferedByServer().toSaslException(); } TransformationMapper trans = new DefaultTransformationMapper(); String[] tokensToChooseFrom = ciphersFromServer.split(String.valueOf(DELIMITER)); for (TransformationSpec ts: trans.getTransformationSpecByStrength(SaslMechanismInformation.Names.DIGEST_MD5, tokensToChooseFrom)) { // take the strongest cipher for (String c: demandedCiphers) { if (c.equals(ts.getToken())) { return ts.getToken(); } } } throw saslDigest.mechNoCommonCipher().toSaslException(); }
@Override public TransformationSpec[] getTransformationSpecWithStrength(String provider, String mechanism, int strength, String... tokens) throws IllegalArgumentException { Assert.checkNotNullParam("tokens", tokens); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } ArrayList<TransformationSpec> tf = new ArrayList<TransformationSpec>(ts.length); for (TransformationSpec t : ts) { for (String token : tokens) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()) && (strength <= t.getStrength()))) { tf.add(t); } } } return tf.toArray(new TransformationSpec[tf.size()]); }
@Override public TransformationSpec getTransformationSpec(String provider, String mechanism, String token) throws IllegalArgumentException { Assert.checkNotNullParam("token", token); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } for (TransformationSpec t : ts) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()))) { return t; } } return null; }
public DefaultTransformationMapper() { transformations.put("DIGEST-MD5", new TransformationSpec[] { // TODO: once digest-md5 PR will be merged change this to // JBOSS_DIGEST_MD5 new TransformationSpec("3des", "DESede/CBC/NoPadding", NO_KEY, HIGH_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4", "RC4", 128, HIGH_STRENGTH, "SunJCA"), new TransformationSpec("des", "DES/CBC/NoPadding", NO_KEY, MEDIUM_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4-56", "RC4", 56, MEDIUM_STRENGTH, "SunJCA"), new TransformationSpec("rc4-40", "RC4", 40, LOW_STRENGTH, "SunJCA") }); // sort all transformation arrays descending by strength for (String mech : transformations.keySet()) { Arrays.sort(transformations.get(mech), (o1, o2) -> { if (o1.getStrength() < o2.getStrength()) { return 1; } else if (o1.getStrength() > o2.getStrength()) { return -1; } else { return 0; } }); } }
/** * Get supported ciphers as comma separated list of cipher-opts by Digest MD5 spec. * * @return comma separated list of ciphers */ static String getSupportedCiphers(String[] demandedCiphers) { TransformationMapper trans = new DefaultTransformationMapper(); if (demandedCiphers == null) { demandedCiphers = CIPHER_OPTS; } StringBuilder ciphers = new StringBuilder(); for (TransformationSpec ts: trans.getTransformationSpecByStrength(SaslMechanismInformation.Names.DIGEST_MD5, demandedCiphers)) { if (ciphers.length() > 0) { ciphers.append(DELIMITER); } ciphers.append(ts.getToken()); } return ciphers.toString(); }
throw saslDigest.mechUnknownCipher(cipher).toSaslException(); ciph = Cipher.getInstance(transformationSpec.getTransformation()); int slash = ciph.getAlgorithm().indexOf('/'); String alg = (slash > -1 ? ciph.getAlgorithm().substring(0, slash) : ciph.getAlgorithm());
@Override public TransformationSpec[] getTransformationSpecWithStrength(String provider, String mechanism, int strength, String... tokens) throws IllegalArgumentException { Assert.checkNotNullParam("tokens", tokens); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } ArrayList<TransformationSpec> tf = new ArrayList<TransformationSpec>(ts.length); for (TransformationSpec t : ts) { for (String token : tokens) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()) && (strength <= t.getStrength()))) { tf.add(t); } } } return tf.toArray(new TransformationSpec[tf.size()]); }
@Override public TransformationSpec getTransformationSpec(String provider, String mechanism, String token) throws IllegalArgumentException { Assert.checkNotNullParam("token", token); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } for (TransformationSpec t : ts) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()))) { return t; } } return null; }
public DefaultTransformationMapper() { transformations.put("DIGEST-MD5", new TransformationSpec[] { // TODO: once digest-md5 PR will be merged change this to // JBOSS_DIGEST_MD5 new TransformationSpec("3des", "DESede/CBC/NoPadding", NO_KEY, HIGH_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4", "RC4", 128, HIGH_STRENGTH, "SunJCA"), new TransformationSpec("des", "DES/CBC/NoPadding", NO_KEY, MEDIUM_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4-56", "RC4", 56, MEDIUM_STRENGTH, "SunJCA"), new TransformationSpec("rc4-40", "RC4", 40, LOW_STRENGTH, "SunJCA") }); // sort all transformation arrays descending by strength for (String mech : transformations.keySet()) { Arrays.sort(transformations.get(mech), (o1, o2) -> { if (o1.getStrength() < o2.getStrength()) { return 1; } else if (o1.getStrength() > o2.getStrength()) { return -1; } else { return 0; } }); } }
/** * Get supported ciphers as comma separated list of cipher-opts by Digest MD5 spec. * * @return comma separated list of ciphers */ static String getSupportedCiphers(String[] demandedCiphers) { TransformationMapper trans = new DefaultTransformationMapper(); if (demandedCiphers == null) { demandedCiphers = CIPHER_OPTS; } StringBuilder ciphers = new StringBuilder(); for (TransformationSpec ts: trans.getTransformationSpecByStrength(SaslMechanismInformation.Names.DIGEST_MD5, demandedCiphers)) { if (ciphers.length() > 0) { ciphers.append(DELIMITER); } ciphers.append(ts.getToken()); } return ciphers.toString(); }
throw saslDigest.mechUnknownCipher(cipher).toSaslException(); ciph = Cipher.getInstance(transformationSpec.getTransformation()); int slash = ciph.getAlgorithm().indexOf('/'); String alg = (slash > -1 ? ciph.getAlgorithm().substring(0, slash) : ciph.getAlgorithm());
@Override public TransformationSpec[] getTransformationSpecWithStrength(String provider, String mechanism, int strength, String... tokens) throws IllegalArgumentException { Assert.checkNotNullParam("tokens", tokens); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } ArrayList<TransformationSpec> tf = new ArrayList<TransformationSpec>(ts.length); for (TransformationSpec t : ts) { for (String token : tokens) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()) && (strength <= t.getStrength()))) { tf.add(t); } } } return tf.toArray(new TransformationSpec[tf.size()]); }
@Override public TransformationSpec getTransformationSpec(String provider, String mechanism, String token) throws IllegalArgumentException { Assert.checkNotNullParam("token", token); TransformationSpec[] ts = transformations.get(mechanism); if (ts == null) { throw log.mechanismNotSupported(mechanism); } for (TransformationSpec t : ts) { if (token.equals(t.getToken()) && (provider == null || provider.equals(t.getProvider()))) { return t; } } return null; }
public DefaultTransformationMapper() { transformations.put("DIGEST-MD5", new TransformationSpec[] { // TODO: once digest-md5 PR will be merged change this to // JBOSS_DIGEST_MD5 new TransformationSpec("3des", "DESede/CBC/NoPadding", NO_KEY, HIGH_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4", "RC4", 128, HIGH_STRENGTH, "SunJCA"), new TransformationSpec("des", "DES/CBC/NoPadding", NO_KEY, MEDIUM_STRENGTH + 1, "SunJCA"), new TransformationSpec("rc4-56", "RC4", 56, MEDIUM_STRENGTH, "SunJCA"), new TransformationSpec("rc4-40", "RC4", 40, LOW_STRENGTH, "SunJCA") }); // sort all transformation arrays descending by strength for (String mech : transformations.keySet()) { Arrays.sort(transformations.get(mech), (o1, o2) -> { if (o1.getStrength() < o2.getStrength()) { return 1; } else if (o1.getStrength() > o2.getStrength()) { return -1; } else { return 0; } }); } }