use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by ResurrectionRemix.
the class SPVerifier method checkName.
private void checkName(Asn1Constructed altName) throws IOException {
Map<String, I18Name> friendlyNames = new HashMap<>();
for (Asn1Object name : altName.getChildren()) {
if (name.getAsn1Class() == Asn1Class.Context && name.getTag() == OtherName) {
Asn1Constructed otherName = (Asn1Constructed) name;
Iterator<Asn1Object> children = otherName.getChildren().iterator();
if (children.hasNext()) {
Asn1Object oidObject = children.next();
if (OidMappings.sIdWfaHotspotFriendlyName.equals(oidObject) && children.hasNext()) {
Asn1Constructed value = castObject(children.next(), Asn1Constructed.class);
String text = castObject(value.getChildren().iterator().next(), Asn1String.class).getString();
I18Name friendlyName = new I18Name(text);
friendlyNames.put(friendlyName.getLanguage(), friendlyName);
}
}
}
}
Log.d(OSUManager.TAG, "Friendly names: " + friendlyNames.values());
for (I18Name osuName : mOSUInfo.getOSUProvider().getNames()) {
I18Name friendlyName = friendlyNames.get(osuName.getLanguage());
if (!osuName.equals(friendlyName)) {
throw new IOException("Friendly name '" + osuName + " not in certificate");
}
}
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by ResurrectionRemix.
the class ESTHandler method unpackPkcs7.
private static List<X509Certificate> unpackPkcs7(ByteBuffer pkcs7) throws IOException, GeneralSecurityException {
Collection<Asn1Object> pkcs7Content = Asn1Decoder.decode(pkcs7);
if (pkcs7Content.size() != 1) {
throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
}
Asn1Object data = pkcs7Content.iterator().next();
if (!data.isConstructed() || !data.matches(sSEQUENCE)) {
throw new IOException("Expected SEQ OF, got " + data.toSimpleString());
} else if (data.getChildren().size() != 2) {
throw new IOException("Expected content info to have two children, got " + data.getChildren().size());
}
Iterator<Asn1Object> children = data.getChildren().iterator();
Asn1Object contentType = children.next();
if (!contentType.equals(Asn1Oid.PKCS7SignedData)) {
throw new IOException("Content not PKCS7 signed data");
}
Asn1Object content = children.next();
if (!content.isConstructed() || !content.matches(sCTXT0)) {
throw new IOException("Expected [CONTEXT 0] with one child, got " + content.toSimpleString() + ", " + content.getChildren().size());
}
Asn1Object signedData = content.getChildren().iterator().next();
Map<Integer, Asn1Object> itemMap = new HashMap<>();
for (Asn1Object item : signedData.getChildren()) {
if (itemMap.put(item.getTag(), item) != null && item.getTag() != Asn1Decoder.TAG_SET) {
throw new IOException("Duplicate item in SignedData: " + item.toSimpleString());
}
}
Asn1Object versionObject = itemMap.get(Asn1Decoder.TAG_INTEGER);
if (versionObject == null || !(versionObject instanceof Asn1Integer)) {
throw new IOException("Bad or missing PKCS7 version: " + versionObject);
}
int pkcs7version = (int) ((Asn1Integer) versionObject).getValue();
Asn1Object innerContentInfo = itemMap.get(Asn1Decoder.TAG_SEQ);
if (innerContentInfo == null || !innerContentInfo.isConstructed() || !innerContentInfo.matches(sSEQUENCE) || innerContentInfo.getChildren().size() != 1) {
throw new IOException("Bad or missing PKCS7 contentInfo");
}
Asn1Object contentID = innerContentInfo.getChildren().iterator().next();
if (pkcs7version == PKCS7DataVersion && !contentID.equals(Asn1Oid.PKCS7Data) || pkcs7version == PKCS7SignedDataVersion && !contentID.equals(Asn1Oid.PKCS7SignedData)) {
throw new IOException("Inner PKCS7 content (" + contentID + ") not expected for version " + pkcs7version);
}
Asn1Object certWrapper = itemMap.get(0);
if (certWrapper == null || !certWrapper.isConstructed() || !certWrapper.matches(sCTXT0)) {
throw new IOException("Expected [CONTEXT 0], got: " + certWrapper);
}
List<X509Certificate> certList = new ArrayList<>(certWrapper.getChildren().size());
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
for (Asn1Object certObject : certWrapper.getChildren()) {
ByteBuffer certOctets = ((Asn1Constructed) certObject).getEncoding();
if (certOctets == null) {
throw new IOException("No cert payload in: " + certObject);
}
byte[] certBytes = new byte[certOctets.remaining()];
certOctets.get(certBytes);
certList.add((X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(certBytes)));
}
return certList;
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by DirtyUnicorns.
the class SPVerifier method checkName.
private void checkName(Asn1Constructed altName) throws IOException {
Map<String, I18Name> friendlyNames = new HashMap<>();
for (Asn1Object name : altName.getChildren()) {
if (name.getAsn1Class() == Asn1Class.Context && name.getTag() == OtherName) {
Asn1Constructed otherName = (Asn1Constructed) name;
Iterator<Asn1Object> children = otherName.getChildren().iterator();
if (children.hasNext()) {
Asn1Object oidObject = children.next();
if (OidMappings.sIdWfaHotspotFriendlyName.equals(oidObject) && children.hasNext()) {
Asn1Constructed value = castObject(children.next(), Asn1Constructed.class);
String text = castObject(value.getChildren().iterator().next(), Asn1String.class).getString();
I18Name friendlyName = new I18Name(text);
friendlyNames.put(friendlyName.getLanguage(), friendlyName);
}
}
}
}
Log.d(OSUManager.TAG, "Friendly names: " + friendlyNames.values());
for (I18Name osuName : mOSUInfo.getOSUProvider().getNames()) {
I18Name friendlyName = friendlyNames.get(osuName.getLanguage());
if (!osuName.equals(friendlyName)) {
throw new IOException("Friendly name '" + osuName + " not in certificate");
}
}
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by DirtyUnicorns.
the class SPVerifier method getImageData.
private static List<LogoTypeImage> getImageData(Asn1Object logoExtension) throws IOException {
Asn1Constructed logo = castObject(logoExtension, Asn1Constructed.class);
Asn1Constructed communityLogo = castObject(logo.getChildren().iterator().next(), Asn1Constructed.class);
if (communityLogo.getTag() != 0) {
throw new IOException("Expected tag [0] for communityLogos");
}
List<LogoTypeImage> images = new ArrayList<>();
Asn1Constructed communityLogoSeq = castObject(communityLogo.getChildren().iterator().next(), Asn1Constructed.class);
for (Asn1Object logoTypeData : communityLogoSeq.getChildren()) {
if (logoTypeData.getTag() != 0) {
throw new IOException("Expected tag [0] for LogotypeData");
}
for (Asn1Object logoTypeImage : castObject(logoTypeData.getChildren().iterator().next(), Asn1Constructed.class).getChildren()) {
// only read the image SEQUENCE and skip any audio [1] tags
if (logoTypeImage.getAsn1Class() == Asn1Class.Universal) {
images.add(new LogoTypeImage(castObject(logoTypeImage, Asn1Constructed.class)));
}
}
}
return images;
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by DirtyUnicorns.
the class ESTHandler method unpackPkcs7.
private static List<X509Certificate> unpackPkcs7(ByteBuffer pkcs7) throws IOException, GeneralSecurityException {
Collection<Asn1Object> pkcs7Content = Asn1Decoder.decode(pkcs7);
if (pkcs7Content.size() != 1) {
throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
}
Asn1Object data = pkcs7Content.iterator().next();
if (!data.isConstructed() || !data.matches(sSEQUENCE)) {
throw new IOException("Expected SEQ OF, got " + data.toSimpleString());
} else if (data.getChildren().size() != 2) {
throw new IOException("Expected content info to have two children, got " + data.getChildren().size());
}
Iterator<Asn1Object> children = data.getChildren().iterator();
Asn1Object contentType = children.next();
if (!contentType.equals(Asn1Oid.PKCS7SignedData)) {
throw new IOException("Content not PKCS7 signed data");
}
Asn1Object content = children.next();
if (!content.isConstructed() || !content.matches(sCTXT0)) {
throw new IOException("Expected [CONTEXT 0] with one child, got " + content.toSimpleString() + ", " + content.getChildren().size());
}
Asn1Object signedData = content.getChildren().iterator().next();
Map<Integer, Asn1Object> itemMap = new HashMap<>();
for (Asn1Object item : signedData.getChildren()) {
if (itemMap.put(item.getTag(), item) != null && item.getTag() != Asn1Decoder.TAG_SET) {
throw new IOException("Duplicate item in SignedData: " + item.toSimpleString());
}
}
Asn1Object versionObject = itemMap.get(Asn1Decoder.TAG_INTEGER);
if (versionObject == null || !(versionObject instanceof Asn1Integer)) {
throw new IOException("Bad or missing PKCS7 version: " + versionObject);
}
int pkcs7version = (int) ((Asn1Integer) versionObject).getValue();
Asn1Object innerContentInfo = itemMap.get(Asn1Decoder.TAG_SEQ);
if (innerContentInfo == null || !innerContentInfo.isConstructed() || !innerContentInfo.matches(sSEQUENCE) || innerContentInfo.getChildren().size() != 1) {
throw new IOException("Bad or missing PKCS7 contentInfo");
}
Asn1Object contentID = innerContentInfo.getChildren().iterator().next();
if (pkcs7version == PKCS7DataVersion && !contentID.equals(Asn1Oid.PKCS7Data) || pkcs7version == PKCS7SignedDataVersion && !contentID.equals(Asn1Oid.PKCS7SignedData)) {
throw new IOException("Inner PKCS7 content (" + contentID + ") not expected for version " + pkcs7version);
}
Asn1Object certWrapper = itemMap.get(0);
if (certWrapper == null || !certWrapper.isConstructed() || !certWrapper.matches(sCTXT0)) {
throw new IOException("Expected [CONTEXT 0], got: " + certWrapper);
}
List<X509Certificate> certList = new ArrayList<>(certWrapper.getChildren().size());
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
for (Asn1Object certObject : certWrapper.getChildren()) {
ByteBuffer certOctets = ((Asn1Constructed) certObject).getEncoding();
if (certOctets == null) {
throw new IOException("No cert payload in: " + certObject);
}
byte[] certBytes = new byte[certOctets.remaining()];
certOctets.get(certBytes);
certList.add((X509Certificate) certFactory.generateCertificate(new ByteArrayInputStream(certBytes)));
}
return certList;
}
Aggregations