OpenSSL を使用して署名メールと暗号化メールを送信できる Android アプリを作成しようとしています。
これまでのところ、Web ブラウザーと Android アプリの両方を使用して、署名付きメールを送信し、検証することができます。
暗号化と復号化についても同様です。
しかし今、Androidアプリから署名付き+暗号化されたメールを送信しようとしています。Exchange サーバーは、Android アプリから送信されたメールを検証/復号化できません。
OWA を使用してこれらのメールを開こうとすると、次のエラーが表示されます。
One or more errors occurred while the message was being loaded. Error: (0x800ccef6)
The digital signature of this message couldn't be validated because an error occurred while the message was being loaded.
このエラー コードの意味について何かヒントはありますか?
更新 1:-暗号化と署名コードの追加。
サインコード:
public static boolean Java_PKCS7Sign(File inputFile, File outputFile, PrivateKey privateKey, X509Certificate certificate, String signingAlgorithm) {
try {
String inputFilePath = inputFile.getAbsolutePath();
String outputFilePath = outputFile.getAbsolutePath();
byte arr[] = android.security.Credentials.convertToPem(certificate);
InputStream certIs = new ByteArrayInputStream(arr);
OpenSSLX509Certificate openSSLcert = OpenSSLX509Certificate.fromX509PemInputStream(certIs);
byte openSSLcertEncoded[] = openSSLcert.getEncoded();
long signCertRef = NativeCrypto.d2i_X509(openSSLcertEncoded);
OpenSSLKey oKey = OpenSSLKey.fromPrivateKey(privateKey);
long evpKeyRef = oKey.getPkeyContext();
//boolean res = PKCS7Sign(signCertRef, pkeyRef, certs, bioRef, flags, a, b)
long arr1[] = new long[0];
return PKCS7Sign(inputFilePath, signCertRef, evpKeyRef, arr1, outputFilePath);
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
上記のコードPKCS7Sign
は、OpenSSL への JNI 呼び出しです。また、署名に使用されるフラグは次のとおりです。int flgs = PKCS7_STREAM | PKCS7_DETACHED | PKCS7_BINARY ;
暗号化コード:
public static boolean Java_PKCS7encrypt(File inputData, File output, X509Certificate[] recipientCertificates, String encryptionAlgorithm) {
if(!inputData.exists() || !output.exists())
return false;
try {
fis = new FileInputStream(inputData);
OpenSSLBIOInputStream bis = new OpenSSLBIOInputStream(fis);
long bioRef = NativeCrypto.create_BIO_InputStream(bis);
int certsRefArrLength = recipientCertificates.length;
long certsRefArr[] = new long[certsRefArrLength];
for (int i = 0; i < certsRefArrLength; i++) {
byte arr[] = android.security.Credentials.convertToPem(recipientCertificates[i]);
InputStream certIs = new ByteArrayInputStream(arr);
OpenSSLX509Certificate openSSLcert = OpenSSLX509Certificate.fromX509PemInputStream(certIs);
byte openSSLcertEncoded[] = openSSLcert.getEncoded();
certsRefArr[i] = NativeCrypto.d2i_X509(openSSLcertEncoded);
}
String outputFilePath = output.getAbsolutePath();
return PKCS7encrypt(bioRef, certsRefArr, outputFilePath, encryptionAlgorithm);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (CertificateEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
return false;
}
サインの場合と同様に、PKCS7encrypt
OpenSSL への JNI 呼び出しです。使用されるフラグは次のとおりです。
int flags = PKCS7_STREAM | PKCS7_BINARY;
そして、暗号化に使われる暗号はcipher = EVP_rc2_40_cbc();