@Override public final ASN1Exception asnInvalidGeneralNameForIpAddressType() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidGeneralNameForIpAddressType$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnIpAddressGeneralNameCannotBeResolved = "ELY07008: IP address general name cannot be resolved";
public void encodeTo(final ASN1Encoder encoder) { encoder.encodeImplicit(getType()); try { encoder.writeEncoded(cert.getEncoded()); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } } }
/** * Encode an ASN.1 set of certificates using the given DER encoder and the * given {@code X509Certificate} chain. * * @param encoder the DER encoder * @param certChain the X.509 certificate chain to encode * @throws ASN1Exception if an error occurs while encoding the given certificate chain */ public static void encodeX509CertificateChain(final DEREncoder encoder, X509Certificate[] certChain) throws ASN1Exception { try { int chainSize = certChain.length; encoder.startSetOf(); for (int i = 0; i < chainSize; i++) { encoder.writeEncoded(certChain[i].getEncoded()); } encoder.endSetOf(); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } }
@Override public final ASN1Exception asnInvalidHighTagNumberForm() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidHighTagNumberForm$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnLengthEncodingExceeds4bytes = "ELY07016: Length encoding exceeds 4 bytes";
/** * Decode the next element from the given DER decoder as an X.509 certificate chain. * * @param decoder the DER decoder * @return the X.509 certificate chain * @throws ASN1Exception if the next element from the given decoder is not an X.509 * certificate chain or if an error occurs while decoding the X.509 certificate chain */ public static X509Certificate[] decodeX509CertificateChain(final DERDecoder decoder) throws ASN1Exception { if (decoder.peekType() != SET_TYPE) { throw saslEntity.asnUnexpectedTag(); } byte[] certChain = decoder.drainElement(); try { CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); certChain[0] = SEQUENCE_TYPE; // CertificateFactory#generateCertPath requires a DER SEQUE CertPath certPath = certFactory.generateCertPath(new ByteArrayInputStream(certChain)); List<? extends Certificate> certs = certPath.getCertificates(); return certs.toArray(new X509Certificate[certs.size()]); } catch (CertificateException e) { throw new ASN1Exception(e); } }
@Override public final ASN1Exception asnInvalidLength() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidLength$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnUnknownTagType = "ELY07022: Unknown tag type: %d";
@Override public String decodeOctetStringAsString(String charSet) throws ASN1Exception { readTag(OCTET_STRING_TYPE); int length = readLength(); byte[] octets = new byte[length]; if ((length != 0) && (bi.drain(octets, 0, length) != length)) { throw log.asnUnexpectedEndOfInput(); } try { return new String(octets, charSet); } catch (UnsupportedEncodingException e) { throw new ASN1Exception(e); } }
@Override public final ASN1Exception asnInvalidGeneralNameType() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidGeneralNameType$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnUnexpectedTag = "ELY07004: Unexpected ASN.1 tag encountered";
trustedAuthority = new CertificateTrustedAuthority((X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(cert))); } catch (CertificateException e) { throw new ASN1Exception(e);
@Override public final ASN1Exception asnInvalidGeneralNameForUriType(final Throwable cause) { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidGeneralNameForUriType$str()), cause); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnInvalidGeneralNameForIpAddressType = "ELY07007: Invalid general name for IP address type";
/** * Recompute and restore the initial context token header for the given token. * * @param token the initial context token without the token header * @return the initial context token with the token header restored * @throws ASN1Exception if the mechanism OID cannot be DER encoded */ private byte[] restoreTokenHeader(byte[] token) throws ASN1Exception { final DEREncoder encoder = new DEREncoder(); encoder.encodeImplicit(APPLICATION_SPECIFIC_MASK, 0); encoder.startSequence(); try { encoder.writeEncoded(mechanism.getDER()); } catch (GSSException e) { throw new ASN1Exception(e); } encoder.writeEncoded(token); encoder.endSequence(); return encoder.getEncoded(); }
@Override public final ASN1Exception asnInvalidNumberOfUnusedBits() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidNumberOfUnusedBits$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnNonZeroLengthForNullTypeTag = "ELY07014: Non-zero length encountered for null type tag";
public void encodeTo(final ASN1Encoder encoder) { encoder.encodeImplicit(getType()); try { encoder.writeEncoded(cert.getEncoded()); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } } }
@Override public final ASN1Exception asnLengthEncodingExceeds4bytes() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnLengthEncodingExceeds4bytes$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnInvalidOidCharacter = "ELY07017: Invalid OID character";
public void encodeTo(final ASN1Encoder encoder) { encoder.encodeImplicit(getType()); try { encoder.writeEncoded(cert.getEncoded()); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } } }
@Override public final ASN1Exception asnInvalidValueForSecondOidComponent() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidValueForSecondOidComponent$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnInvalidLength = "ELY07021: Invalid length";
public void encodeTo(final ASN1Encoder encoder) { encoder.encodeImplicit(getType()); try { encoder.writeEncoded(cert.getEncoded()); } catch (CertificateEncodingException e) { throw new ASN1Exception(e); } } }
@Override public final ASN1Exception asnOidMustHaveAtLeast2Components() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnOidMustHaveAtLeast2Components$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnInvalidValueForFirstOidComponent = "ELY07019: Invalid value for first OID component; expected 0, 1, or 2";
@Override public String decodeOctetStringAsString(String charSet) throws ASN1Exception { readTag(OCTET_STRING_TYPE); int length = readLength(); byte[] octets = new byte[length]; if ((length != 0) && (bi.drain(octets, 0, length) != length)) { throw log.asnUnexpectedEndOfInput(); } try { return new String(octets, charSet); } catch (UnsupportedEncodingException e) { throw new ASN1Exception(e); } }
@Override public final ASN1Exception asnInvalidLengthForBooleanTypeTag() { final ASN1Exception result = new ASN1Exception(String.format(getLoggingLocale(), asnInvalidLengthForBooleanTypeTag$str())); final StackTraceElement[] st = result.getStackTrace(); result.setStackTrace(Arrays.copyOfRange(st, 1, st.length)); return result; } private static final String asnInvalidGeneralNameForUriTypeMissingScheme = "ELY07025: Invalid general name for URI type: missing scheme";