/** * Parse a XmppAddr value as specified in RFC 6120. * * @param xmppAddr The ASN.1 representation of the xmppAddr value (cannot be null). * @return The parsed xmppAddr value. */ protected String parseOtherNameXmppAddr( ASN1Primitive xmppAddr ) { // Get the nested object if the value is an ASN1TaggedObject or a sub-type of it if (ASN1TaggedObject.class.isAssignableFrom(xmppAddr.getClass())) { ASN1TaggedObject taggedObject = (ASN1TaggedObject) xmppAddr; ASN1Primitive objectPrimitive = taggedObject.getObject(); if (ASN1String.class.isAssignableFrom(objectPrimitive.getClass())) { return ((ASN1String) objectPrimitive).getString(); } } // RFC 6120 says that this should be a UTF8String. Lets be tolerant and allow all text-based values. return ( (ASN1String) xmppAddr ).getString(); }
/** * Parses a SRVName value as specified by RFC 4985. * * This method parses the argument value as a DNS SRV Resource Record. Only when the parsed value refers to an XMPP * related service, the corresponding DNS domain name is returned (minus the service name). * * @param srvName The ASN.1 representation of the srvName value (cannot be null). * @return an XMPP address value, or null when the record does not relate to XMPP. */ protected String parseOtherNameDnsSrv( ASN1Primitive srvName ) { // RFC 4985 says that this should be a IA5 String. Lets be tolerant and allow all text-based values. final String value = ( (ASN1String) srvName ).getString(); if ( value.toLowerCase().startsWith( "_xmpp-server." ) ) { return value.substring( "_xmpp-server.".length() ); } else if ( value.toLowerCase().startsWith( "_xmpp-client." ) ) { return value.substring( "_xmpp-client.".length() ); } else { // Not applicable to XMPP. Ignore. Log.debug( "srvName value '{}' of id-on-dnsSRV record is neither _xmpp-server nor _xmpp-client. It is being ignored.", value ); return null; } }
/** * Parse a UPN value * * @param value The ASN.1 representation of the UPN (cannot be null). * @return The parsed UPN value. */ protected String parseOtherNameUpn( ASN1Primitive value ) { String otherName = null; if (value instanceof ASN1TaggedObject) { ASN1TaggedObject taggedObject = (ASN1TaggedObject) value; ASN1Primitive objectPrimitive = taggedObject.getObject(); if (objectPrimitive instanceof ASN1String) { otherName = ((ASN1String)objectPrimitive).getString(); } } if (otherName == null) { Log.warn("UPN type unexpected, UPN extraction failed: " + value.getClass().getName() + ":" + value.toString()); } else { Log.debug("UPN from certificate has value of: " + otherName ); } return otherName; } }
private String asString(ASN1Primitive primitive) { if (primitive == null || primitive instanceof ASN1Null) { return ""; } if (primitive instanceof ASN1String) { return ((ASN1String) primitive).getString(); } if (primitive instanceof DERUTCTime) { return ((DERUTCTime) primitive).getAdjustedTime(); } if (primitive instanceof DERGeneralizedTime) { return ((DERGeneralizedTime) primitive).getTime(); } if (primitive instanceof ASN1ObjectIdentifier) { switch (((ASN1ObjectIdentifier) primitive).getId()) { case "1.3.6.1.5.5.7.8.5": return "xmppAddr"; default: return primitive.toString(); } } return primitive.toString(); } }
/** * Returns the stored <code>String</code> object. * * @return the stored text as a <code>String</code>. */ public String getString() { return contents.getString(); } }
/** * Parse a XmppAddr value as specified in RFC 6120. * * @param xmppAddr The ASN.1 representation of the xmppAddr value (cannot be null). * @return The parsed xmppAddr value. */ protected String parseOtherNameXmppAddr( ASN1Primitive xmppAddr ) { // RFC 6120 says that this should be a UTF8String. Lets be tolerant and allow all text-based values. return ( (ASN1String) xmppAddr ).getString(); }
/** * Returns the stored <code>String</code> object. * * @return the stored text as a <code>String</code>. */ public String getString() { return contents.getString(); } }
/** * Gets the role name as a <code>java.lang.String</code> object. * @return the role name of this RoleSyntax represented as a * <code>java.lang.String</code> object. */ public String getRoleNameAsString() { ASN1String str = (ASN1String)this.roleName.getName(); return str.getString(); }
/** * Gets the role name as a <code>java.lang.String</code> object. * @return the role name of this RoleSyntax represented as a * <code>java.lang.String</code> object. */ public String getRoleNameAsString() { ASN1String str = (ASN1String)this.roleName.getName(); return str.getString(); }
private String canonicalize(String s) { String value = Strings.toLowerCase(s.trim()); if (value.length() > 0 && value.charAt(0) == '#') { ASN1Primitive obj = decodeObject(value); if (obj instanceof ASN1String) { value = Strings.toLowerCase(((ASN1String)obj).getString().trim()); } } return value; }
private static String parseGn(GeneralName gn) { try { if (GeneralName.uniformResourceIdentifier == gn.getTagNo()) { ASN1String str = (ASN1String) ((DERTaggedObject) gn.toASN1Primitive()).getObject(); return str.getString(); } } catch (Exception e) { LOG.warn("Unable to parse GN " + gn, e); } return null; }
public static String rdnValueToString(ASN1Encodable value) { Args.notNull(value, "value"); if (value instanceof ASN1String && !(value instanceof DERUniversalString)) { return ((ASN1String) value).getString(); } else { try { return "#" + Hex.encode( value.toASN1Primitive().getEncoded(ASN1Encoding.DER)); } catch (IOException ex) { throw new IllegalArgumentException("other value has no encoded form"); } } }
public static CmpUtf8Pairs extract(InfoTypeAndValue[] regInfos) { if (regInfos != null) { for (InfoTypeAndValue regInfo : regInfos) { if (CMPObjectIdentifiers.regInfo_utf8Pairs.equals(regInfo.getInfoType())) { String regInfoValue = ((ASN1String) regInfo.getInfoValue()).getString(); return new CmpUtf8Pairs(regInfoValue); } } } return null; }
public static CmpUtf8Pairs extract(final InfoTypeAndValue[] regInfos) { if (regInfos == null) { return null; } for (InfoTypeAndValue regInfo : regInfos) { if (CMPObjectIdentifiers.regInfo_utf8Pairs.equals(regInfo.getInfoType())) { String regInfoValue = ((ASN1String) regInfo.getInfoValue()).getString(); return new CmpUtf8Pairs(regInfoValue); } } return null; }
public static CmpUtf8Pairs extract(AttributeTypeAndValue[] atvs) { if (atvs != null) { for (AttributeTypeAndValue atv : atvs) { if (CMPObjectIdentifiers.regInfo_utf8Pairs.equals(atv.getType())) { String regInfoValue = ((ASN1String) atv.getValue()).getString(); return new CmpUtf8Pairs(regInfoValue); } } } return null; }
public static CmpUtf8Pairs extract(InfoTypeAndValue[] regInfos) { if (regInfos != null) { for (InfoTypeAndValue regInfo : regInfos) { if (CMPObjectIdentifiers.regInfo_utf8Pairs.equals(regInfo.getInfoType())) { String regInfoValue = ((ASN1String) regInfo.getInfoValue()).getString(); return new CmpUtf8Pairs(regInfoValue); } } } return null; }
public static CmpUtf8Pairs extract(final AttributeTypeAndValue[] atvs) { if (atvs == null) { return null; } for (AttributeTypeAndValue atv : atvs) { if (CMPObjectIdentifiers.regInfo_utf8Pairs.equals(atv.getType())) { String regInfoValue = ((ASN1String) atv.getValue()).getString(); return new CmpUtf8Pairs(regInfoValue); } } return null; }
public static CmpUtf8Pairs extract(AttributeTypeAndValue[] atvs) { if (atvs != null) { for (AttributeTypeAndValue atv : atvs) { if (CMPObjectIdentifiers.regInfo_utf8Pairs.equals(atv.getType())) { String regInfoValue = ((ASN1String) atv.getValue()).getString(); return new CmpUtf8Pairs(regInfoValue); } } } return null; }
private static String getChallengePassword(CertificationRequestInfo csr) { ASN1Set attrs = csr.getAttributes(); for (int i = 0; i < attrs.size(); i++) { Attribute attr = Attribute.getInstance(attrs.getObjectAt(i)); if (PKCSObjectIdentifiers.pkcs_9_at_challengePassword.equals(attr.getAttrType())) { ASN1String str = (ASN1String) attr.getAttributeValues()[0]; return str.getString(); } } return null; }
public static String getChallengePassword(CertificationRequestInfo csr) { Args.notNull(csr, "csr"); ASN1Set attrs = csr.getAttributes(); for (int i = 0; i < attrs.size(); i++) { Attribute attr = Attribute.getInstance(attrs.getObjectAt(i)); if (PKCSObjectIdentifiers.pkcs_9_at_challengePassword.equals(attr.getAttrType())) { ASN1String str = (ASN1String) attr.getAttributeValues()[0]; return str.getString(); } } return null; }