mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-18 23:39:40 +01:00
Compare commits
14 Commits
main
...
jdk-18.0.1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b416ea00c | ||
|
|
56b0dfffb7 | ||
|
|
715b432ae5 | ||
|
|
29ce3ae34b | ||
|
|
bab7d80317 | ||
|
|
d0e26d3e7c | ||
|
|
f357fdefad | ||
|
|
6caa851218 | ||
|
|
cbcb39119d | ||
|
|
a2d1450011 | ||
|
|
b260c5c939 | ||
|
|
419f9ccd83 | ||
|
|
d2ee0647a5 | ||
|
|
6d45bba88a |
@@ -28,12 +28,12 @@
|
|||||||
|
|
||||||
DEFAULT_VERSION_FEATURE=18
|
DEFAULT_VERSION_FEATURE=18
|
||||||
DEFAULT_VERSION_INTERIM=0
|
DEFAULT_VERSION_INTERIM=0
|
||||||
DEFAULT_VERSION_UPDATE=0
|
DEFAULT_VERSION_UPDATE=1
|
||||||
DEFAULT_VERSION_PATCH=0
|
DEFAULT_VERSION_PATCH=0
|
||||||
DEFAULT_VERSION_EXTRA1=0
|
DEFAULT_VERSION_EXTRA1=0
|
||||||
DEFAULT_VERSION_EXTRA2=0
|
DEFAULT_VERSION_EXTRA2=0
|
||||||
DEFAULT_VERSION_EXTRA3=0
|
DEFAULT_VERSION_EXTRA3=0
|
||||||
DEFAULT_VERSION_DATE=2022-03-22
|
DEFAULT_VERSION_DATE=2022-04-19
|
||||||
DEFAULT_VERSION_CLASSFILE_MAJOR=62 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
|
DEFAULT_VERSION_CLASSFILE_MAJOR=62 # "`$EXPR $DEFAULT_VERSION_FEATURE + 44`"
|
||||||
DEFAULT_VERSION_CLASSFILE_MINOR=0
|
DEFAULT_VERSION_CLASSFILE_MINOR=0
|
||||||
DEFAULT_VERSION_DOCS_API_SINCE=11
|
DEFAULT_VERSION_DOCS_API_SINCE=11
|
||||||
|
|||||||
@@ -1029,7 +1029,6 @@ int ExceptionMessageBuilder::do_instruction(int bci) {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Bytecodes::_arraylength:
|
case Bytecodes::_arraylength:
|
||||||
// The return type of arraylength is wrong in the bytecodes table (T_VOID).
|
|
||||||
stack->pop(1);
|
stack->pop(1);
|
||||||
stack->push(bci, T_INT);
|
stack->push(bci, T_INT);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -471,7 +471,7 @@ void Bytecodes::initialize() {
|
|||||||
def(_new , "new" , "bkk" , NULL , T_OBJECT , 1, true );
|
def(_new , "new" , "bkk" , NULL , T_OBJECT , 1, true );
|
||||||
def(_newarray , "newarray" , "bc" , NULL , T_OBJECT , 0, true );
|
def(_newarray , "newarray" , "bc" , NULL , T_OBJECT , 0, true );
|
||||||
def(_anewarray , "anewarray" , "bkk" , NULL , T_OBJECT , 0, true );
|
def(_anewarray , "anewarray" , "bkk" , NULL , T_OBJECT , 0, true );
|
||||||
def(_arraylength , "arraylength" , "b" , NULL , T_VOID , 0, true );
|
def(_arraylength , "arraylength" , "b" , NULL , T_INT , 0, true );
|
||||||
def(_athrow , "athrow" , "b" , NULL , T_VOID , -1, true );
|
def(_athrow , "athrow" , "b" , NULL , T_VOID , -1, true );
|
||||||
def(_checkcast , "checkcast" , "bkk" , NULL , T_OBJECT , 0, true );
|
def(_checkcast , "checkcast" , "bkk" , NULL , T_OBJECT , 0, true );
|
||||||
def(_instanceof , "instanceof" , "bkk" , NULL , T_INT , 0, true );
|
def(_instanceof , "instanceof" , "bkk" , NULL , T_INT , 0, true );
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -1580,7 +1580,7 @@ bool LibraryCallKit::inline_string_char_access(bool is_store) {
|
|||||||
if (is_store) {
|
if (is_store) {
|
||||||
access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED);
|
access_store_at(value, adr, TypeAryPtr::BYTES, ch, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED);
|
||||||
} else {
|
} else {
|
||||||
ch = access_load_at(value, adr, TypeAryPtr::BYTES, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD);
|
ch = access_load_at(value, adr, TypeAryPtr::BYTES, TypeInt::CHAR, T_CHAR, IN_HEAP | MO_UNORDERED | C2_MISMATCHED | C2_CONTROL_DEPENDENT_LOAD | C2_UNKNOWN_CONTROL_LOAD);
|
||||||
set_result(ch);
|
set_result(ch);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -68,6 +68,25 @@ public final class KeychainStore extends KeyStoreSpi {
|
|||||||
|
|
||||||
Certificate cert;
|
Certificate cert;
|
||||||
long certRef; // SecCertificateRef for this key
|
long certRef; // SecCertificateRef for this key
|
||||||
|
|
||||||
|
// Each KeyStore.TrustedCertificateEntry have 2 attributes:
|
||||||
|
// 1. "trustSettings" -> trustSettings.toString()
|
||||||
|
// 2. "2.16.840.1.113894.746875.1.1" -> trustedKeyUsageValue
|
||||||
|
// The 1st one is mainly for debugging use. The 2nd one is similar
|
||||||
|
// to the attribute with the same key in a PKCS12KeyStore.
|
||||||
|
|
||||||
|
// The SecTrustSettingsCopyTrustSettings() output for this certificate
|
||||||
|
// inside the KeyChain in its original array of CFDictionaryRef objects
|
||||||
|
// structure with values dumped as strings. For each trust, an extra
|
||||||
|
// entry "SecPolicyOid" is added whose value is the OID for this trust.
|
||||||
|
// The extra entries are used to construct trustedKeyUsageValue.
|
||||||
|
List<Map<String, String>> trustSettings;
|
||||||
|
|
||||||
|
// One or more OIDs defined in http://oidref.com/1.2.840.113635.100.1.
|
||||||
|
// It can also be "2.5.29.37.0" for a self-signed certificate with
|
||||||
|
// an empty trust settings. This value is never empty. When there are
|
||||||
|
// multiple OID values, it takes the form of "[1.1.1, 1.1.2]".
|
||||||
|
String trustedKeyUsageValue;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -300,6 +319,35 @@ public final class KeychainStore extends KeyStoreSpi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record LocalAttr(String name, String value)
|
||||||
|
implements KeyStore.Entry.Attribute {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public KeyStore.Entry engineGetEntry(String alias, KeyStore.ProtectionParameter protParam)
|
||||||
|
throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableEntryException {
|
||||||
|
if (engineIsCertificateEntry(alias)) {
|
||||||
|
Object entry = entries.get(alias.toLowerCase());
|
||||||
|
if (entry instanceof TrustedCertEntry tEntry) {
|
||||||
|
return new KeyStore.TrustedCertificateEntry(
|
||||||
|
tEntry.cert, Set.of(
|
||||||
|
new LocalAttr(KnownOIDs.ORACLE_TrustedKeyUsage.value(), tEntry.trustedKeyUsageValue),
|
||||||
|
new LocalAttr("trustSettings", tEntry.trustSettings.toString())));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return super.engineGetEntry(alias, protParam);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the creation date of the entry identified by the given alias.
|
* Returns the creation date of the entry identified by the given alias.
|
||||||
*
|
*
|
||||||
@@ -453,55 +501,12 @@ public final class KeychainStore extends KeyStoreSpi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Assigns the given certificate to the given alias.
|
* Adding trusted certificate entry is not supported.
|
||||||
*
|
|
||||||
* <p>If the given alias already exists in this keystore and identifies a
|
|
||||||
* <i>trusted certificate entry</i>, the certificate associated with it is
|
|
||||||
* overridden by the given certificate.
|
|
||||||
*
|
|
||||||
* @param alias the alias name
|
|
||||||
* @param cert the certificate
|
|
||||||
*
|
|
||||||
* @exception KeyStoreException if the given alias already exists and does
|
|
||||||
* not identify a <i>trusted certificate entry</i>, or this operation
|
|
||||||
* fails for some other reason.
|
|
||||||
*/
|
*/
|
||||||
public void engineSetCertificateEntry(String alias, Certificate cert)
|
public void engineSetCertificateEntry(String alias, Certificate cert)
|
||||||
throws KeyStoreException
|
throws KeyStoreException {
|
||||||
{
|
throw new KeyStoreException("Cannot set trusted certificate entry." +
|
||||||
permissionCheck();
|
" Use the macOS \"security add-trusted-cert\" command instead.");
|
||||||
|
|
||||||
synchronized(entries) {
|
|
||||||
|
|
||||||
Object entry = entries.get(alias.toLowerCase());
|
|
||||||
if ((entry != null) && (entry instanceof KeyEntry)) {
|
|
||||||
throw new KeyStoreException
|
|
||||||
("Cannot overwrite key entry with certificate");
|
|
||||||
}
|
|
||||||
|
|
||||||
// This will be slow, but necessary. Enumerate the values and then see if the cert matches the one in the trusted cert entry.
|
|
||||||
// Security framework doesn't support the same certificate twice in a keychain.
|
|
||||||
Collection<Object> allValues = entries.values();
|
|
||||||
|
|
||||||
for (Object value : allValues) {
|
|
||||||
if (value instanceof TrustedCertEntry) {
|
|
||||||
TrustedCertEntry tce = (TrustedCertEntry)value;
|
|
||||||
if (tce.cert.equals(cert)) {
|
|
||||||
throw new KeyStoreException("Keychain does not support mulitple copies of same certificate.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
TrustedCertEntry trustedCertEntry = new TrustedCertEntry();
|
|
||||||
trustedCertEntry.cert = cert;
|
|
||||||
trustedCertEntry.date = new Date();
|
|
||||||
String lowerAlias = alias.toLowerCase();
|
|
||||||
if (entries.get(lowerAlias) != null) {
|
|
||||||
deletedEntries.put(lowerAlias, entries.get(lowerAlias));
|
|
||||||
}
|
|
||||||
entries.put(lowerAlias, trustedCertEntry);
|
|
||||||
addedEntries.put(lowerAlias, trustedCertEntry);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -680,10 +685,7 @@ public final class KeychainStore extends KeyStoreSpi {
|
|||||||
String alias = e.nextElement();
|
String alias = e.nextElement();
|
||||||
Object entry = addedEntries.get(alias);
|
Object entry = addedEntries.get(alias);
|
||||||
if (entry instanceof TrustedCertEntry) {
|
if (entry instanceof TrustedCertEntry) {
|
||||||
TrustedCertEntry tce = (TrustedCertEntry)entry;
|
// Cannot set trusted certificate entry
|
||||||
Certificate certElem;
|
|
||||||
certElem = tce.cert;
|
|
||||||
tce.certRef = addCertificateToKeychain(alias, certElem);
|
|
||||||
} else {
|
} else {
|
||||||
KeyEntry keyEntry = (KeyEntry)entry;
|
KeyEntry keyEntry = (KeyEntry)entry;
|
||||||
|
|
||||||
@@ -778,9 +780,28 @@ public final class KeychainStore extends KeyStoreSpi {
|
|||||||
private native void _scanKeychain();
|
private native void _scanKeychain();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Callback method from _scanKeychain. If a trusted certificate is found, this method will be called.
|
* Callback method from _scanKeychain. If a trusted certificate is found,
|
||||||
|
* this method will be called.
|
||||||
|
*
|
||||||
|
* inputTrust is a list of strings in groups. Each group contains key/value
|
||||||
|
* pairs for one trust setting and ends with a null. Thus the size of the
|
||||||
|
* whole list is (2 * s_1 + 1) + (2 * s_2 + 1) + ... + (2 * s_n + 1),
|
||||||
|
* where s_i is the size of mapping for the i'th trust setting,
|
||||||
|
* and n is the number of trust settings. Ex:
|
||||||
|
*
|
||||||
|
* key1 for trust1
|
||||||
|
* value1 for trust1
|
||||||
|
* ..
|
||||||
|
* null (end of trust1)
|
||||||
|
* key1 for trust2
|
||||||
|
* value1 for trust2
|
||||||
|
* ...
|
||||||
|
* null (end of trust2)
|
||||||
|
* ...
|
||||||
|
* null (end if trust_n)
|
||||||
*/
|
*/
|
||||||
private void createTrustedCertEntry(String alias, long keychainItemRef, long creationDate, byte[] derStream) {
|
private void createTrustedCertEntry(String alias, List<String> inputTrust,
|
||||||
|
long keychainItemRef, long creationDate, byte[] derStream) {
|
||||||
TrustedCertEntry tce = new TrustedCertEntry();
|
TrustedCertEntry tce = new TrustedCertEntry();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -791,6 +812,69 @@ public final class KeychainStore extends KeyStoreSpi {
|
|||||||
tce.cert = cert;
|
tce.cert = cert;
|
||||||
tce.certRef = keychainItemRef;
|
tce.certRef = keychainItemRef;
|
||||||
|
|
||||||
|
tce.trustSettings = new ArrayList<>();
|
||||||
|
Map<String,String> tmpMap = new LinkedHashMap<>();
|
||||||
|
for (int i = 0; i < inputTrust.size(); i++) {
|
||||||
|
if (inputTrust.get(i) == null) {
|
||||||
|
tce.trustSettings.add(tmpMap);
|
||||||
|
if (i < inputTrust.size() - 1) {
|
||||||
|
// Prepare an empty map for the next trust setting.
|
||||||
|
// Do not just clear(), must be a new object.
|
||||||
|
// Only create if not at end of list.
|
||||||
|
tmpMap = new LinkedHashMap<>();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
tmpMap.put(inputTrust.get(i), inputTrust.get(i+1));
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean isSelfSigned;
|
||||||
|
try {
|
||||||
|
cert.verify(cert.getPublicKey());
|
||||||
|
isSelfSigned = true;
|
||||||
|
} catch (Exception e) {
|
||||||
|
isSelfSigned = false;
|
||||||
|
}
|
||||||
|
if (tce.trustSettings.isEmpty()) {
|
||||||
|
if (isSelfSigned) {
|
||||||
|
// If a self-signed certificate has an empty trust settings,
|
||||||
|
// trust it for all purposes
|
||||||
|
tce.trustedKeyUsageValue = KnownOIDs.anyExtendedKeyUsage.value();
|
||||||
|
} else {
|
||||||
|
// Otherwise, return immediately. The certificate is not
|
||||||
|
// added into entries.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
List<String> values = new ArrayList<>();
|
||||||
|
for (var oneTrust : tce.trustSettings) {
|
||||||
|
var result = oneTrust.get("kSecTrustSettingsResult");
|
||||||
|
// https://developer.apple.com/documentation/security/sectrustsettingsresult?language=objc
|
||||||
|
// 1 = kSecTrustSettingsResultTrustRoot, 2 = kSecTrustSettingsResultTrustAsRoot
|
||||||
|
// If missing, a default value of kSecTrustSettingsResultTrustRoot is assumed
|
||||||
|
// for self-signed certificates (see doc for SecTrustSettingsCopyTrustSettings).
|
||||||
|
// Note that the same SecPolicyOid can appear in multiple trust settings
|
||||||
|
// for different kSecTrustSettingsAllowedError and/or kSecTrustSettingsPolicyString.
|
||||||
|
if ((result == null && isSelfSigned)
|
||||||
|
|| "1".equals(result) || "2".equals(result)) {
|
||||||
|
// When no kSecTrustSettingsPolicy, it means everything
|
||||||
|
String oid = oneTrust.getOrDefault("SecPolicyOid",
|
||||||
|
KnownOIDs.anyExtendedKeyUsage.value());
|
||||||
|
if (!values.contains(oid)) {
|
||||||
|
values.add(oid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (values.isEmpty()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (values.size() == 1) {
|
||||||
|
tce.trustedKeyUsageValue = values.get(0);
|
||||||
|
} else {
|
||||||
|
tce.trustedKeyUsageValue = values.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
// Make a creation date.
|
// Make a creation date.
|
||||||
if (creationDate != 0)
|
if (creationDate != 0)
|
||||||
tce.date = new Date(creationDate);
|
tce.date = new Date(creationDate);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2011, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -368,6 +368,14 @@ errOut:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define ADD(list, str) { \
|
||||||
|
jobject localeObj = (*env)->NewStringUTF(env, [str UTF8String]); \
|
||||||
|
(*env)->CallBooleanMethod(env, list, jm_listAdd, localeObj); \
|
||||||
|
(*env)->DeleteLocalRef(env, localeObj); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define ADDNULL(list) (*env)->CallBooleanMethod(env, list, jm_listAdd, NULL)
|
||||||
|
|
||||||
static void addCertificatesToKeystore(JNIEnv *env, jobject keyStore)
|
static void addCertificatesToKeystore(JNIEnv *env, jobject keyStore)
|
||||||
{
|
{
|
||||||
// Search the user keychain list for all X509 certificates.
|
// Search the user keychain list for all X509 certificates.
|
||||||
@@ -379,8 +387,15 @@ static void addCertificatesToKeystore(JNIEnv *env, jobject keyStore)
|
|||||||
jclass jc_KeychainStore = (*env)->FindClass(env, "apple/security/KeychainStore");
|
jclass jc_KeychainStore = (*env)->FindClass(env, "apple/security/KeychainStore");
|
||||||
CHECK_NULL(jc_KeychainStore);
|
CHECK_NULL(jc_KeychainStore);
|
||||||
jmethodID jm_createTrustedCertEntry = (*env)->GetMethodID(
|
jmethodID jm_createTrustedCertEntry = (*env)->GetMethodID(
|
||||||
env, jc_KeychainStore, "createTrustedCertEntry", "(Ljava/lang/String;JJ[B)V");
|
env, jc_KeychainStore, "createTrustedCertEntry", "(Ljava/lang/String;Ljava/util/List;JJ[B)V");
|
||||||
CHECK_NULL(jm_createTrustedCertEntry);
|
CHECK_NULL(jm_createTrustedCertEntry);
|
||||||
|
jclass jc_arrayListClass = (*env)->FindClass(env, "java/util/ArrayList");
|
||||||
|
CHECK_NULL(jc_arrayListClass);
|
||||||
|
jmethodID jm_arrayListCons = (*env)->GetMethodID(env, jc_arrayListClass, "<init>", "()V");
|
||||||
|
CHECK_NULL(jm_arrayListCons);
|
||||||
|
jmethodID jm_listAdd = (*env)->GetMethodID(env, jc_arrayListClass, "add", "(Ljava/lang/Object;)Z");
|
||||||
|
CHECK_NULL(jm_listAdd);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
searchResult = SecKeychainSearchCopyNext(keychainItemSearch, &theItem);
|
searchResult = SecKeychainSearchCopyNext(keychainItemSearch, &theItem);
|
||||||
|
|
||||||
@@ -401,12 +416,50 @@ static void addCertificatesToKeystore(JNIEnv *env, jobject keyStore)
|
|||||||
goto errOut;
|
goto errOut;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Only add certificates with trusted settings
|
||||||
|
CFArrayRef trustSettings;
|
||||||
|
if (SecTrustSettingsCopyTrustSettings(certRef, kSecTrustSettingsDomainUser, &trustSettings)
|
||||||
|
== errSecItemNotFound) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// See KeychainStore::createTrustedCertEntry for content of inputTrust
|
||||||
|
jobject inputTrust = (*env)->NewObject(env, jc_arrayListClass, jm_arrayListCons);
|
||||||
|
CHECK_NULL(inputTrust);
|
||||||
|
|
||||||
|
// Dump everything inside trustSettings into inputTrust
|
||||||
|
CFIndex count = CFArrayGetCount(trustSettings);
|
||||||
|
for (int i = 0; i < count; i++) {
|
||||||
|
CFDictionaryRef oneTrust = (CFDictionaryRef) CFArrayGetValueAtIndex(trustSettings, i);
|
||||||
|
CFIndex size = CFDictionaryGetCount(oneTrust);
|
||||||
|
const void * keys [size];
|
||||||
|
const void * values [size];
|
||||||
|
CFDictionaryGetKeysAndValues(oneTrust, keys, values);
|
||||||
|
for (int j = 0; j < size; j++) {
|
||||||
|
NSString* s = [NSString stringWithFormat:@"%@", keys[j]];
|
||||||
|
ADD(inputTrust, s);
|
||||||
|
s = [NSString stringWithFormat:@"%@", values[j]];
|
||||||
|
ADD(inputTrust, s);
|
||||||
|
}
|
||||||
|
SecPolicyRef certPolicy;
|
||||||
|
certPolicy = (SecPolicyRef)CFDictionaryGetValue(oneTrust, kSecTrustSettingsPolicy);
|
||||||
|
if (certPolicy != NULL) {
|
||||||
|
CFDictionaryRef policyDict = SecPolicyCopyProperties(certPolicy);
|
||||||
|
ADD(inputTrust, @"SecPolicyOid");
|
||||||
|
NSString* s = [NSString stringWithFormat:@"%@", CFDictionaryGetValue(policyDict, @"SecPolicyOid")];
|
||||||
|
ADD(inputTrust, s);
|
||||||
|
CFRelease(policyDict);
|
||||||
|
}
|
||||||
|
ADDNULL(inputTrust);
|
||||||
|
}
|
||||||
|
CFRelease(trustSettings);
|
||||||
|
|
||||||
// Find the creation date.
|
// Find the creation date.
|
||||||
jlong creationDate = getModDateFromItem(env, theItem);
|
jlong creationDate = getModDateFromItem(env, theItem);
|
||||||
|
|
||||||
// Call back to the Java object to create Java objects corresponding to this security object.
|
// Call back to the Java object to create Java objects corresponding to this security object.
|
||||||
jlong nativeRef = ptr_to_jlong(certRef);
|
jlong nativeRef = ptr_to_jlong(certRef);
|
||||||
(*env)->CallVoidMethod(env, keyStore, jm_createTrustedCertEntry, alias, nativeRef, creationDate, certData);
|
(*env)->CallVoidMethod(env, keyStore, jm_createTrustedCertEntry, alias, inputTrust, nativeRef, creationDate, certData);
|
||||||
JNU_CHECK_EXCEPTION(env);
|
JNU_CHECK_EXCEPTION(env);
|
||||||
}
|
}
|
||||||
} while (searchResult == noErr);
|
} while (searchResult == noErr);
|
||||||
@@ -522,8 +575,8 @@ NSString* JavaStringToNSString(JNIEnv *env, jstring jstr) {
|
|||||||
/*
|
/*
|
||||||
* Class: apple_security_KeychainStore
|
* Class: apple_security_KeychainStore
|
||||||
* Method: _addItemToKeychain
|
* Method: _addItemToKeychain
|
||||||
* Signature: (Ljava/lang/String;[B)I
|
* Signature: (Ljava/lang/String;Z[B[C)J
|
||||||
*/
|
*/
|
||||||
JNIEXPORT jlong JNICALL Java_apple_security_KeychainStore__1addItemToKeychain
|
JNIEXPORT jlong JNICALL Java_apple_security_KeychainStore__1addItemToKeychain
|
||||||
(JNIEnv *env, jobject this, jstring alias, jboolean isCertificate, jbyteArray rawDataObj, jcharArray passwordObj)
|
(JNIEnv *env, jobject this, jstring alias, jboolean isCertificate, jbyteArray rawDataObj, jcharArray passwordObj)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -362,7 +362,8 @@ abstract class DSA extends SignatureSpi {
|
|||||||
s = new BigInteger(1, s.toByteArray());
|
s = new BigInteger(1, s.toByteArray());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((r.compareTo(presetQ) == -1) && (s.compareTo(presetQ) == -1)) {
|
if ((r.compareTo(presetQ) == -1) && (s.compareTo(presetQ) == -1)
|
||||||
|
&& r.signum() > 0 && s.signum() > 0) {
|
||||||
BigInteger w = generateW(presetP, presetQ, presetG, s);
|
BigInteger w = generateW(presetP, presetQ, presetG, s);
|
||||||
BigInteger v = generateV(presetY, presetP, presetQ, presetG, w, r);
|
BigInteger v = generateV(presetY, presetP, presetQ, presetG, w, r);
|
||||||
return v.equals(r);
|
return v.equals(r);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -2209,6 +2209,9 @@ public final class Main {
|
|||||||
out.println(mf);
|
out.println(mf);
|
||||||
dumpCert(cert, out);
|
dumpCert(cert, out);
|
||||||
} else if (debug) {
|
} else if (debug) {
|
||||||
|
for (var attr : keyStore.getEntry(alias, null).getAttributes()) {
|
||||||
|
System.out.println("Attribute " + attr.getName() + ": " + attr.getValue());
|
||||||
|
}
|
||||||
out.println(cert.toString());
|
out.println(cert.toString());
|
||||||
} else {
|
} else {
|
||||||
out.println("trustedCertEntry, ");
|
out.println("trustedCertEntry, ");
|
||||||
|
|||||||
@@ -144,15 +144,14 @@ class DerIndefLenConverter {
|
|||||||
* then skip the tag and its 1 byte length of zero.
|
* then skip the tag and its 1 byte length of zero.
|
||||||
*/
|
*/
|
||||||
private void writeTag() {
|
private void writeTag() {
|
||||||
if (dataPos == dataSize) {
|
while (dataPos < dataSize) {
|
||||||
return;
|
assert dataPos + 1 < dataSize;
|
||||||
}
|
if (isEOC(data, dataPos)) {
|
||||||
assert dataPos + 1 < dataSize;
|
dataPos += 2; // skip tag and length
|
||||||
if (isEOC(data, dataPos)) {
|
} else {
|
||||||
dataPos += 2; // skip tag and length
|
newData[newDataPos++] = data[dataPos++];
|
||||||
writeTag();
|
break;
|
||||||
} else {
|
}
|
||||||
newData[newDataPos++] = data[dataPos++];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 1996, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 1996, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -365,7 +365,7 @@ public final class ObjectIdentifier implements Serializable {
|
|||||||
if ((encoding[i] & 0x80) == 0) {
|
if ((encoding[i] & 0x80) == 0) {
|
||||||
// one section [fromPos..i]
|
// one section [fromPos..i]
|
||||||
if (i - fromPos + 1 > 4) {
|
if (i - fromPos + 1 > 4) {
|
||||||
BigInteger big = new BigInteger(pack(encoding,
|
BigInteger big = new BigInteger(1, pack(encoding,
|
||||||
fromPos, i-fromPos+1, 7, 8));
|
fromPos, i-fromPos+1, 7, 8));
|
||||||
if (fromPos == 0) {
|
if (fromPos == 0) {
|
||||||
result[which++] = 2;
|
result[which++] = 2;
|
||||||
@@ -434,7 +434,7 @@ public final class ObjectIdentifier implements Serializable {
|
|||||||
sb.append('.');
|
sb.append('.');
|
||||||
}
|
}
|
||||||
if (i - fromPos + 1 > 4) { // maybe big integer
|
if (i - fromPos + 1 > 4) { // maybe big integer
|
||||||
BigInteger big = new BigInteger(
|
BigInteger big = new BigInteger(1,
|
||||||
pack(encoding, fromPos, i-fromPos+1, 7, 8));
|
pack(encoding, fromPos, i-fromPos+1, 7, 8));
|
||||||
if (fromPos == 0) {
|
if (fromPos == 0) {
|
||||||
// first section encoded with more than 4 bytes,
|
// first section encoded with more than 4 bytes,
|
||||||
@@ -684,6 +684,10 @@ public final class ObjectIdentifier implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static void checkOidSize(int oidLength) throws IOException {
|
private static void checkOidSize(int oidLength) throws IOException {
|
||||||
|
if (oidLength < 0) {
|
||||||
|
throw new IOException("ObjectIdentifier encoded length was " +
|
||||||
|
"negative: " + oidLength);
|
||||||
|
}
|
||||||
if (oidLength > MAXIMUM_OID_SIZE) {
|
if (oidLength > MAXIMUM_OID_SIZE) {
|
||||||
throw new IOException(
|
throw new IOException(
|
||||||
"ObjectIdentifier encoded length exceeds " +
|
"ObjectIdentifier encoded length exceeds " +
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ import javax.imageio.stream.ImageInputStream;
|
|||||||
|
|
||||||
import com.sun.imageio.plugins.common.I18N;
|
import com.sun.imageio.plugins.common.I18N;
|
||||||
import com.sun.imageio.plugins.common.ImageUtil;
|
import com.sun.imageio.plugins.common.ImageUtil;
|
||||||
|
import com.sun.imageio.plugins.common.ReaderUtil;
|
||||||
|
|
||||||
/** This class is the Java Image IO plugin reader for BMP images.
|
/** This class is the Java Image IO plugin reader for BMP images.
|
||||||
* It may subsample the image, clip the image, select sub-bands,
|
* It may subsample the image, clip the image, select sub-bands,
|
||||||
@@ -1519,9 +1520,8 @@ public class BMPImageReader extends ImageReader implements BMPConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read till we have the whole image
|
// Read till we have the whole image
|
||||||
byte[] values = new byte[imSize];
|
byte[] values = ReaderUtil.
|
||||||
int bytesRead = 0;
|
staggeredReadByteStream(iis, imSize);
|
||||||
iis.readFully(values, 0, imSize);
|
|
||||||
|
|
||||||
// Since data is compressed, decompress it
|
// Since data is compressed, decompress it
|
||||||
decodeRLE8(imSize, padding, values, bdata);
|
decodeRLE8(imSize, padding, values, bdata);
|
||||||
@@ -1703,8 +1703,8 @@ public class BMPImageReader extends ImageReader implements BMPConstants {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Read till we have the whole image
|
// Read till we have the whole image
|
||||||
byte[] values = new byte[imSize];
|
byte[] values = ReaderUtil.
|
||||||
iis.readFully(values, 0, imSize);
|
staggeredReadByteStream(iis, imSize);
|
||||||
|
|
||||||
// Decompress the RLE4 compressed data.
|
// Decompress the RLE4 compressed data.
|
||||||
decodeRLE4(imSize, padding, values, bdata);
|
decodeRLE4(imSize, padding, values, bdata);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2005, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -28,6 +28,8 @@ package com.sun.imageio.plugins.common;
|
|||||||
import java.awt.Point;
|
import java.awt.Point;
|
||||||
import java.awt.Rectangle;
|
import java.awt.Rectangle;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
import javax.imageio.stream.ImageInputStream;
|
import javax.imageio.stream.ImageInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -213,4 +215,47 @@ public class ReaderUtil {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An utility method to allocate and initialize a byte array
|
||||||
|
* step by step with pre-defined limit, instead of allocating
|
||||||
|
* a large array up-front based on the length derived from
|
||||||
|
* an image header.
|
||||||
|
*
|
||||||
|
* @param iis a {@code ImageInputStream} to decode data and store
|
||||||
|
* it in byte array.
|
||||||
|
* @param length the size of data to decode
|
||||||
|
*
|
||||||
|
* @return array of size length when decode succeeeds
|
||||||
|
*
|
||||||
|
* @throws IOException if decoding of stream fails
|
||||||
|
*/
|
||||||
|
public static byte[] staggeredReadByteStream(ImageInputStream iis,
|
||||||
|
int length) throws IOException {
|
||||||
|
final int UNIT_SIZE = 1024000;
|
||||||
|
byte[] decodedData;
|
||||||
|
if (length < UNIT_SIZE) {
|
||||||
|
decodedData = new byte[length];
|
||||||
|
iis.readFully(decodedData, 0, length);
|
||||||
|
} else {
|
||||||
|
int bytesToRead = length;
|
||||||
|
int bytesRead = 0;
|
||||||
|
List<byte[]> bufs = new ArrayList<>();
|
||||||
|
while (bytesToRead != 0) {
|
||||||
|
int sz = Math.min(bytesToRead, UNIT_SIZE);
|
||||||
|
byte[] unit = new byte[sz];
|
||||||
|
iis.readFully(unit, 0, sz);
|
||||||
|
bufs.add(unit);
|
||||||
|
bytesRead += sz;
|
||||||
|
bytesToRead -= sz;
|
||||||
|
}
|
||||||
|
decodedData = new byte[bytesRead];
|
||||||
|
int copiedBytes = 0;
|
||||||
|
for (byte[] ba : bufs) {
|
||||||
|
System.arraycopy(ba, 0, decodedData, copiedBytes, ba.length);
|
||||||
|
copiedBytes += ba.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return decodedData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2018, 2020, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2018, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -30,6 +30,7 @@ import sun.security.util.ArrayUtil;
|
|||||||
import sun.security.util.math.*;
|
import sun.security.util.math.*;
|
||||||
import static sun.security.ec.ECOperations.IntermediateValueException;
|
import static sun.security.ec.ECOperations.IntermediateValueException;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
import java.security.ProviderException;
|
import java.security.ProviderException;
|
||||||
import java.security.spec.*;
|
import java.security.spec.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@@ -200,7 +201,8 @@ public class ECDSAOperations {
|
|||||||
|
|
||||||
IntegerFieldModuloP field = ecOps.getField();
|
IntegerFieldModuloP field = ecOps.getField();
|
||||||
IntegerFieldModuloP orderField = ecOps.getOrderField();
|
IntegerFieldModuloP orderField = ecOps.getOrderField();
|
||||||
int length = (orderField.getSize().bitLength() + 7) / 8;
|
BigInteger mod = orderField.getSize();
|
||||||
|
int length = (mod.bitLength() + 7) / 8;
|
||||||
|
|
||||||
byte[] r;
|
byte[] r;
|
||||||
byte[] s;
|
byte[] s;
|
||||||
@@ -218,6 +220,13 @@ public class ECDSAOperations {
|
|||||||
System.arraycopy(sig, encodeLength, s, length - encodeLength, encodeLength);
|
System.arraycopy(sig, encodeLength, s, length - encodeLength, encodeLength);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BigInteger rb = new BigInteger(1, r);
|
||||||
|
BigInteger sb = new BigInteger(1, s);
|
||||||
|
if (rb.signum() == 0 || sb.signum() == 0
|
||||||
|
|| rb.compareTo(mod) >= 0 || sb.compareTo(mod) >= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ArrayUtil.reverse(r);
|
ArrayUtil.reverse(r);
|
||||||
ArrayUtil.reverse(s);
|
ArrayUtil.reverse(s);
|
||||||
IntegerModuloP ri = orderField.getElement(r);
|
IntegerModuloP ri = orderField.getElement(r);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
|
* Copyright (c) 2016, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
package jdk.test.lib;
|
package jdk.test.lib;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
@@ -275,5 +276,63 @@ public class SecurityTools {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a temporary keychain in macOS and use it. The original
|
||||||
|
// keychains will be restored when the object is closed.
|
||||||
|
public static class TemporaryKeychain implements Closeable {
|
||||||
|
// name of new keychain
|
||||||
|
private final String newChain;
|
||||||
|
// names of the original keychains
|
||||||
|
private final List<String> oldChains;
|
||||||
|
|
||||||
|
public TemporaryKeychain(String name) {
|
||||||
|
Path p = Path.of(name + ".keychain-db");
|
||||||
|
newChain = p.toAbsolutePath().toString();
|
||||||
|
try {
|
||||||
|
oldChains = ProcessTools.executeProcess("security", "list-keychains")
|
||||||
|
.shouldHaveExitValue(0)
|
||||||
|
.getStdout()
|
||||||
|
.lines()
|
||||||
|
.map(String::trim)
|
||||||
|
.map(x -> x.startsWith("\"") ? x.substring(1, x.length() - 1) : x)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (!Files.exists(p)) {
|
||||||
|
ProcessTools.executeProcess("security", "create-keychain", "-p", "changeit", newChain)
|
||||||
|
.shouldHaveExitValue(0);
|
||||||
|
}
|
||||||
|
ProcessTools.executeProcess("security", "unlock-keychain", "-p", "changeit", newChain)
|
||||||
|
.shouldHaveExitValue(0);
|
||||||
|
ProcessTools.executeProcess("security", "list-keychains", "-s", newChain)
|
||||||
|
.shouldHaveExitValue(0);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (t instanceof RuntimeException re) {
|
||||||
|
throw re;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String chain() {
|
||||||
|
return newChain;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void close() throws IOException {
|
||||||
|
List<String> cmds = new ArrayList<>();
|
||||||
|
cmds.addAll(List.of("security", "list-keychains", "-s"));
|
||||||
|
cmds.addAll(oldChains);
|
||||||
|
try {
|
||||||
|
ProcessTools.executeProcess(cmds.toArray(new String[0]))
|
||||||
|
.shouldHaveExitValue(0);
|
||||||
|
} catch (Throwable t) {
|
||||||
|
if (t instanceof RuntimeException re) {
|
||||||
|
throw re;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException(t);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user