use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by ResurrectionRemix.
the class SPVerifier method getExtension.
private static Asn1Object getExtension(X509Certificate certificate, String extension) throws GeneralSecurityException, IOException {
byte[] data = certificate.getExtensionValue(extension);
if (data == null) {
return null;
}
Asn1Octets octetString = (Asn1Octets) Asn1Decoder.decode(ByteBuffer.wrap(data)).iterator().next();
Asn1Constructed sequence = castObject(Asn1Decoder.decode(ByteBuffer.wrap(octetString.getOctets())).iterator().next(), Asn1Constructed.class);
Log.d(OSUManager.TAG, "Extension " + extension + ": " + sequence);
return sequence;
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by ResurrectionRemix.
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 ResurrectionRemix.
the class ESTHandler method execute.
public void execute(boolean reenroll) throws IOException, GeneralSecurityException {
URL caURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(), mURL.getFile() + CACERT_PATH);
HTTPResponse response;
try (HTTPHandler httpHandler = new HTTPHandler(StandardCharsets.ISO_8859_1, mSocketFactory, mUser, mPassword)) {
response = httpHandler.doGetHTTP(caURL);
if (!"application/pkcs7-mime".equals(response.getHeaders().get(HTTPMessage.ContentTypeHeader))) {
throw new IOException("Unexpected Content-Type: " + response.getHeaders().get(HTTPMessage.ContentTypeHeader));
}
ByteBuffer octetBuffer = response.getBinaryPayload();
Collection<Asn1Object> pkcs7Content1 = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : pkcs7Content1) {
Log.d(TAG, "---");
Log.d(TAG, asn1Object.toString());
}
Log.d(TAG, CACERT_PATH);
mCACerts.addAll(unpackPkcs7(octetBuffer));
for (X509Certificate certificate : mCACerts) {
Log.d(TAG, "CA-Cert: " + certificate.getSubjectX500Principal());
}
/*
byte[] octets = new byte[octetBuffer.remaining()];
octetBuffer.duplicate().get(octets);
for (byte b : octets) {
System.out.printf("%02x ", b & 0xff);
}
Log.d(TAG, );
*/
/* + BC
try {
byte[] octets = new byte[octetBuffer.remaining()];
octetBuffer.duplicate().get(octets);
ASN1InputStream asnin = new ASN1InputStream(octets);
for (int n = 0; n < 100; n++) {
ASN1Primitive object = asnin.readObject();
if (object == null) {
break;
}
parseObject(object, 0);
}
}
catch (Throwable t) {
t.printStackTrace();
}
Collection<Asn1Object> pkcs7Content = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : pkcs7Content) {
Log.d(TAG, asn1Object);
}
if (pkcs7Content.size() != 1) {
throw new IOException("Unexpected pkcs 7 container: " + pkcs7Content.size());
}
Asn1Constructed pkcs7Root = (Asn1Constructed) pkcs7Content.iterator().next();
Iterator<Asn1ID> certPath = Arrays.asList(Pkcs7CertPath).iterator();
Asn1Object certObject = pkcs7Root.findObject(certPath);
if (certObject == null || certPath.hasNext()) {
throw new IOException("Failed to find cert; returned object " + certObject +
", path " + (certPath.hasNext() ? "short" : "exhausted"));
}
ByteBuffer certOctets = certObject.getPayload();
if (certOctets == null) {
throw new IOException("No cert payload in: " + certObject);
}
byte[] certBytes = new byte[certOctets.remaining()];
certOctets.get(certBytes);
CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
Certificate cert = certFactory.generateCertificate(new ByteArrayInputStream(certBytes));
Log.d(TAG, "EST Cert: " + cert);
*/
URL csrURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(), mURL.getFile() + CSR_PATH);
response = httpHandler.doGetHTTP(csrURL);
octetBuffer = response.getBinaryPayload();
byte[] csrData = buildCSR(octetBuffer, mOMADMAdapter, httpHandler);
/**/
Collection<Asn1Object> o = Asn1Decoder.decode(ByteBuffer.wrap(csrData));
Log.d(TAG, "CSR:");
Log.d(TAG, o.iterator().next().toString());
Log.d(TAG, "End CSR.");
/**/
URL enrollURL = new URL(mURL.getProtocol(), mURL.getHost(), mURL.getPort(), mURL.getFile() + (reenroll ? SIMPLE_REENROLL_PATH : SIMPLE_ENROLL_PATH));
String data = Base64.encodeToString(csrData, Base64.DEFAULT);
octetBuffer = httpHandler.exchangeBinary(enrollURL, data, "application/pkcs10");
Collection<Asn1Object> pkcs7Content2 = Asn1Decoder.decode(octetBuffer);
for (Asn1Object asn1Object : pkcs7Content2) {
Log.d(TAG, "---");
Log.d(TAG, asn1Object.toString());
}
mClientCerts.addAll(unpackPkcs7(octetBuffer));
for (X509Certificate cert : mClientCerts) {
Log.d(TAG, cert.toString());
}
}
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by DirtyUnicorns.
the class SPVerifier method getExtension.
private static Asn1Object getExtension(X509Certificate certificate, String extension) throws GeneralSecurityException, IOException {
byte[] data = certificate.getExtensionValue(extension);
if (data == null) {
return null;
}
Asn1Octets octetString = (Asn1Octets) Asn1Decoder.decode(ByteBuffer.wrap(data)).iterator().next();
Asn1Constructed sequence = castObject(Asn1Decoder.decode(ByteBuffer.wrap(octetString.getOctets())).iterator().next(), Asn1Constructed.class);
Log.d(OSUManager.TAG, "Extension " + extension + ": " + sequence);
return sequence;
}
use of com.android.hotspot2.asn1.Asn1Constructed in project android_frameworks_base by crdroidandroid.
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");
}
}
}
Aggregations