bool OTSignatureMetadata::operator==(const OTSignatureMetadata& rhs) const { return ((HasMetadata() == rhs.HasMetadata()) && (GetKeyType() == rhs.GetKeyType()) && (FirstCharNymID() == rhs.FirstCharNymID()) && (FirstCharMasterCredID() == rhs.FirstCharMasterCredID()) && (FirstCharChildCredID() == rhs.FirstCharChildCredID())); }
bool CryptoKey::ReadStructuredClone(JSStructuredCloneReader* aReader) { nsNSSShutDownPreventionLock locker; if (isAlreadyShutDown()) { return false; } // Ensure that NSS is initialized. if (!EnsureNSSInitializedChromeOrContent()) { return false; } uint32_t version; CryptoBuffer sym, priv, pub; bool read = JS_ReadUint32Pair(aReader, &mAttributes, &version) && (version == CRYPTOKEY_SC_VERSION) && ReadBuffer(aReader, sym) && ReadBuffer(aReader, priv) && ReadBuffer(aReader, pub) && mAlgorithm.ReadStructuredClone(aReader); if (!read) { return false; } if (sym.Length() > 0 && !mSymKey.Assign(sym)) { return false; } if (priv.Length() > 0) { mPrivateKey = CryptoKey::PrivateKeyFromPkcs8(priv, locker); } if (pub.Length() > 0) { mPublicKey = CryptoKey::PublicKeyFromSpki(pub, locker); } // Ensure that what we've read is consistent // If the attributes indicate a key type, should have a key of that type if (!((GetKeyType() == SECRET && mSymKey.Length() > 0) || (GetKeyType() == PRIVATE && mPrivateKey) || (GetKeyType() == PUBLIC && mPublicKey))) { return false; } return true; }
bool CryptoKey::ReadStructuredClone(JSStructuredCloneReader* aReader) { nsNSSShutDownPreventionLock locker; if (isAlreadyShutDown()) { return false; } uint32_t zero; CryptoBuffer sym, priv, pub; nsRefPtr<KeyAlgorithm> algorithm; bool read = JS_ReadUint32Pair(aReader, &mAttributes, &zero) && ReadBuffer(aReader, sym) && ReadBuffer(aReader, priv) && ReadBuffer(aReader, pub) && (algorithm = KeyAlgorithm::Create(mGlobal, aReader)); if (!read) { return false; } if (sym.Length() > 0) { mSymKey = sym; } if (priv.Length() > 0) { mPrivateKey = CryptoKey::PrivateKeyFromPkcs8(priv, locker); } if (pub.Length() > 0) { mPublicKey = CryptoKey::PublicKeyFromSpki(pub, locker); } mAlgorithm = algorithm; // Ensure that what we've read is consistent // If the attributes indicate a key type, should have a key of that type if (!((GetKeyType() == SECRET && mSymKey.Length() > 0) || (GetKeyType() == PRIVATE && mPrivateKey) || (GetKeyType() == PUBLIC && mPublicKey))) { return false; } return true; }
// NSS exports private EC keys without the CKA_EC_POINT attribute, i.e. the // public value. To properly export the private key to JWK or PKCS #8 we need // the public key data though and so we use this method to augment a private // key with data from the given public key. nsresult CryptoKey::AddPublicKeyData(SECKEYPublicKey* aPublicKey) { // This should be a private key. MOZ_ASSERT(GetKeyType() == PRIVATE); // There should be a private NSS key with type 'EC'. MOZ_ASSERT(mPrivateKey && mPrivateKey->keyType == ecKey); // The given public key should have the same key type. MOZ_ASSERT(aPublicKey->keyType == mPrivateKey->keyType); nsNSSShutDownPreventionLock locker; // Read EC params. ScopedAutoSECItem params; SECStatus rv = PK11_ReadRawAttribute(PK11_TypePrivKey, mPrivateKey.get(), CKA_EC_PARAMS, ¶ms); if (rv != SECSuccess) { return NS_ERROR_DOM_OPERATION_ERR; } // Read private value. ScopedAutoSECItem value; rv = PK11_ReadRawAttribute(PK11_TypePrivKey, mPrivateKey.get(), CKA_VALUE, &value); if (rv != SECSuccess) { return NS_ERROR_DOM_OPERATION_ERR; } SECItem* point = &aPublicKey->u.ec.publicValue; CK_OBJECT_CLASS privateKeyValue = CKO_PRIVATE_KEY; CK_BBOOL falseValue = CK_FALSE; CK_KEY_TYPE ecValue = CKK_EC; CK_ATTRIBUTE keyTemplate[9] = { { CKA_CLASS, &privateKeyValue, sizeof(privateKeyValue) }, { CKA_KEY_TYPE, &ecValue, sizeof(ecValue) }, { CKA_TOKEN, &falseValue, sizeof(falseValue) }, { CKA_SENSITIVE, &falseValue, sizeof(falseValue) }, { CKA_PRIVATE, &falseValue, sizeof(falseValue) }, // PrivateKeyFromPrivateKeyTemplate sets the ID. { CKA_ID, nullptr, 0 }, { CKA_EC_PARAMS, params.data, params.len }, { CKA_EC_POINT, point->data, point->len }, { CKA_VALUE, value.data, value.len }, }; mPrivateKey = PrivateKeyFromPrivateKeyTemplate(keyTemplate, ArrayLength(keyTemplate)); NS_ENSURE_TRUE(mPrivateKey, NS_ERROR_DOM_OPERATION_ERR); return NS_OK; }
void CInputProviderMacOsHid::SetInitialBindValues(IOHIDDeviceRef device) { CFArrayRef elements = IOHIDDeviceCopyMatchingElements(device, nullptr, 0); for(int i = 0; i < CFArrayGetCount(elements); i++) { IOHIDElementRef elementRef = (IOHIDElementRef)CFArrayGetValueAtIndex(elements, i); uint32 usagePage = IOHIDElementGetUsagePage(elementRef); if( (usagePage != kHIDPage_GenericDesktop) && (usagePage != kHIDPage_Button)) { continue; } IOHIDValueRef valueRef; if(IOHIDDeviceGetValue(device, elementRef, &valueRef) != kIOReturnSuccess) { continue; } CFIndex value = IOHIDValueGetIntegerValue(valueRef); IOHIDElementType type = IOHIDElementGetType(elementRef); uint32 usage = IOHIDElementGetUsage(elementRef); BINDINGTARGET tgt; tgt.providerId = PROVIDER_ID; tgt.deviceId = GetDeviceID(device); tgt.keyId = usage; tgt.keyType = GetKeyType(usage, type); switch(type) { case kIOHIDElementTypeInput_Misc: case kIOHIDElementTypeInput_Button: case kIOHIDElementTypeInput_Axis: OnInput(tgt, value); break; default: break; } } }
void CInputProviderMacOsHid::InputValueCallback(DEVICE_INFO* deviceInfo, IOReturn result, void* sender, IOHIDValueRef valueRef) { if(!OnInput) return; IOHIDElementRef elementRef = IOHIDValueGetElement(valueRef); uint32 usagePage = IOHIDElementGetUsagePage(elementRef); if( (usagePage != kHIDPage_GenericDesktop) && (usagePage != kHIDPage_Button)) { return; } uint32 usage = IOHIDElementGetUsage(elementRef); CFIndex value = IOHIDValueGetIntegerValue(valueRef); IOHIDElementType type = IOHIDElementGetType(elementRef); BINDINGTARGET tgt; tgt.providerId = PROVIDER_ID; tgt.deviceId = deviceInfo->deviceId; tgt.keyId = usage; tgt.keyType = GetKeyType(usage, type); OnInput(tgt, value); }
wxString pgOperatorClass::GetSql(ctlTree *browser) { if (sql.IsNull()) { sql = wxT("-- Operator Class: ") + GetName() + wxT("\n\n") + wxT("-- DROP OPERATOR CLASS ") + GetQuotedFullIdentifier() + wxT(" USING ") + GetAccessMethod() + wxT(";") + wxT("\n\nCREATE OPERATOR CLASS ") + GetQuotedFullIdentifier(); if (GetOpcDefault()) sql += wxT(" DEFAULT"); sql += wxT("\n FOR TYPE ") + GetInType() + wxT(" USING ") + GetAccessMethod() + wxT(" AS"); unsigned int i; bool needComma = false; for (i = 0 ; i < operators.Count() ; i++) { if (needComma) sql += wxT(","); sql += wxT("\n OPERATOR ") + operators.Item(i); needComma = true; } for (i = 0 ; i < functions.Count() ; i++) { if (needComma) sql += wxT(","); sql += wxT("\n FUNCTION ") + quotedFunctions.Item(i); needComma = true; } AppendIfFilled(sql, wxT("\n STORAGE "), GetKeyType()); sql += wxT(";\n"); } return sql; }
int KGObjectPropertyEditDlg::ShowPropertyTable( CString szNamePlate, CString szTemplate, CString szIniFile ) { m_listProperty.DeleteAllItems(); m_arrayPropertyListItem.RemoveAll(); m_szCurIniFileName = szIniFile; SetWindowText(m_szWindowTextt + " 正在编辑 : " + m_szCurIniFileName); SAFE_RELEASE(m_pIniFile); m_pIniFile = g_OpenIniFile(szTemplate.GetBuffer()); IIniFile* pIniFile = g_OpenIniFile(szIniFile); IIniFile* pNameFile = g_OpenIniFile(szNamePlate.GetBuffer()); if (!pNameFile) return FALSE; if (!m_pIniFile) return FALSE; if (!pIniFile) return FALSE; char szSection[256] = ""; char szKey[256] = ""; char szPlate[256] = ""; char szValue[512] = ""; char szType[256] = ""; UINT uIndex = 0; while (m_pIniFile->GetNextSection(szSection, szSection)) { PropertyListItem item(szSection, szSection); m_arrayPropertyListItem.Add(item); pNameFile->GetString( szSection, "Title", "未知标题", szPlate, sizeof(szPlate) ); m_listProperty.InsertItem (uIndex, NULL); m_listProperty.SetItemText(uIndex, 0, szPlate); //m_listProperty.SetItemData(uIndex, VALUE_TITLE); uIndex++; *szKey = '\0'; while (m_pIniFile->GetNextKey(szSection, szKey, szKey)) { pNameFile->GetString( "Globe", szKey, "未知键名", szPlate, sizeof(szPlate) ); if (CString(szPlate) == "未知键名") { pNameFile->GetString( szSection, szKey, "未知键名", szPlate, sizeof(szPlate) ); } CString szKeyType = CString(szKey) + CString("Type"); pNameFile->GetString( "Globe", szKeyType.GetBuffer(), "VALUE_UNKNOW", szType, sizeof(szType) ); if (CString(szType) == "VALUE_UNKNOW") { pNameFile->GetString( szSection, szKeyType.GetBuffer(), "STRING", szType, sizeof(szType) ); } m_pIniFile->GetString( szSection, szKey, "未知键值", szValue, sizeof(szValue) ); pIniFile->GetString( szSection, szKey, szValue, szValue, sizeof(szValue) ); m_pIniFile->WriteString(szSection, szKey, szValue); PropertyListItem item(szSection, szKey); m_arrayPropertyListItem.Add(item); m_listProperty.InsertItem (uIndex, NULL); m_listProperty.SetItemText(uIndex, 0, szPlate); m_listProperty.SetItemText(uIndex, 1, szValue); m_listProperty.SetItemData(uIndex, GetKeyType(CString(szType))); uIndex++; } } pIniFile->Release(); pNameFile->Release(); return TRUE; }
void pgOperatorClass::ShowTreeDetail(ctlTree *browser, frmMain *form, ctlListView *properties, ctlSQLBox *sqlPane) { if (!expandedKids) { expandedKids = true; pgSet *set; if (!GetConnection()->BackendMinimumVersion(8, 3)) { set = ExecuteSet( wxT("SELECT amopstrategy, amopreqcheck, oprname, lt.typname as lefttype, rt.typname as righttype\n") wxT(" FROM pg_amop am\n") wxT(" JOIN pg_operator op ON amopopr=op.oid\n") wxT(" LEFT OUTER JOIN pg_type lt ON lt.oid=oprleft\n") wxT(" LEFT OUTER JOIN pg_type rt ON rt.oid=oprright\n") wxT(" WHERE amopclaid=") + GetOidStr() + wxT("\n") wxT(" ORDER BY amopstrategy")); } else if (!GetConnection()->BackendMinimumVersion(8, 4)) { set = ExecuteSet( wxT("SELECT amopstrategy, amopreqcheck, oprname, lt.typname as lefttype, rt.typname as righttype\n") wxT(" FROM pg_amop am\n") wxT(" JOIN pg_operator op ON amopopr=op.oid\n") wxT(" JOIN pg_opfamily opf ON amopfamily = opf.oid\n") wxT(" JOIN pg_opclass opc ON opf.oid = opcfamily\n") wxT(" LEFT OUTER JOIN pg_type lt ON lt.oid=oprleft\n") wxT(" LEFT OUTER JOIN pg_type rt ON rt.oid=oprright\n") wxT(" WHERE opc.oid=") + GetOidStr() + wxT("\n") wxT(" AND amopmethod = opf.opfmethod\n") wxT(" AND amoplefttype = op.oprleft AND amoprighttype = op.oprright\n") wxT(" ORDER BY amopstrategy")); } else { set = ExecuteSet( wxT("SELECT amopstrategy, oprname, lt.typname as lefttype, rt.typname as righttype\n") wxT(" FROM pg_amop am\n") wxT(" JOIN pg_operator op ON amopopr=op.oid\n") wxT(" JOIN pg_opfamily opf ON amopfamily = opf.oid\n") wxT(" JOIN pg_opclass opc ON opf.oid = opcfamily\n") wxT(" LEFT OUTER JOIN pg_type lt ON lt.oid=oprleft\n") wxT(" LEFT OUTER JOIN pg_type rt ON rt.oid=oprright\n") wxT(" WHERE opc.oid=") + GetOidStr() + wxT("\n") wxT(" AND amopmethod = opf.opfmethod\n") wxT(" AND amoplefttype = op.oprleft AND amoprighttype = op.oprright\n") wxT(" ORDER BY amopstrategy")); } if (set) { while (!set->Eof()) { wxString str = set->GetVal(wxT("amopstrategy")) + wxT(" ") + set->GetVal(wxT("oprname")); wxString lt = set->GetVal(wxT("lefttype")); wxString rt = set->GetVal(wxT("righttype")); if (lt == GetInType() && (rt.IsEmpty() || rt == GetInType())) lt = wxEmptyString; if (rt == GetInType() && lt.IsEmpty()) rt = wxEmptyString; if (!lt.IsEmpty() || !rt.IsEmpty()) { str += wxT("("); if (!lt.IsEmpty()) { str += lt; if (!rt.IsEmpty()) str += wxT(", "); } if (!rt.IsEmpty()) str += rt; str += wxT(")"); } if (!GetConnection()->BackendMinimumVersion(8, 4)) { if (set->GetBool(wxT("amopreqcheck"))) str += wxT(" RECHECK"); } operators.Add(str); set->MoveNext(); } delete set; } if (!GetConnection()->BackendMinimumVersion(8, 3)) { set = ExecuteSet( wxT("SELECT amprocnum, amproc::oid\n") wxT(" FROM pg_amproc am\n") wxT(" WHERE amopclaid=") + GetOidStr() + wxT("\n") wxT(" ORDER BY amprocnum")); } else { set = ExecuteSet( wxT("SELECT amprocnum, amproc::oid\n") wxT(" FROM pg_amproc am\n") wxT(" JOIN pg_opfamily opf ON amprocfamily = opf.oid\n") wxT(" JOIN pg_opclass opc ON opf.oid = opcfamily\n") wxT(" WHERE opc.oid=") + GetOidStr() + wxT("\n") wxT(" AND amproclefttype = opc.opcintype AND amprocrighttype = opc.opcintype\n") wxT(" ORDER BY amprocnum")); } if (set) { while (!set->Eof()) { wxString amproc = set->GetVal(wxT("amproc")); functionOids.Add(amproc); // We won't build a PG_FUNCTIONS collection under OperatorClass, so we create // temporary function items pgFunction *function = functionFactory.AppendFunctions(this, GetSchema(), 0, wxT(" WHERE pr.oid=") + amproc); if (function) { functions.Add(set->GetVal(wxT("amprocnum")) + wxT(" ") + function->GetFullName()); quotedFunctions.Add(set->GetVal(wxT("amprocnum")) + wxT(" ") + function->GetQuotedFullIdentifier() + wxT("(") + function->GetArgSigList() + wxT(")")); delete function; } set->MoveNext(); } delete set; } } if (properties) { CreateListColumns(properties); properties->AppendItem(_("Name"), GetName()); properties->AppendItem(_("OID"), GetOid()); properties->AppendItem(_("Owner"), GetOwner()); properties->AppendYesNoItem(_("Default?"), GetOpcDefault()); properties->AppendItem(_("For type"), GetInType()); properties->AppendItem(_("Access method"), GetAccessMethod()); if (GetConnection()->BackendMinimumVersion(8, 3)) properties->AppendItem(_("Family"), GetFamily()); if (!GetKeyType().IsEmpty()) properties->AppendItem(_("Storage"), GetKeyType()); unsigned int i; for (i = 0 ; i < operators.Count() ; i++) properties->AppendItem(wxT("OPERATOR"), operators.Item(i)); for (i = 0 ; i < functions.Count() ; i++) properties->AppendItem(wxT("FUNCTION"), functions.Item(i)); properties->AppendYesNoItem(_("System operator class?"), GetSystemObject()); if (GetConnection()->BackendMinimumVersion(7, 5)) properties->AppendItem(_("Comment"), firstLineOnly(GetComment())); } }
// NSS exports private EC keys without the CKA_EC_POINT attribute, i.e. the // public value. To properly export the private key to JWK or PKCS #8 we need // the public key data though and so we use this method to augment a private // key with data from the given public key. nsresult CryptoKey::AddPublicKeyData(SECKEYPublicKey* aPublicKey) { // This should be a private key. MOZ_ASSERT(GetKeyType() == PRIVATE); // There should be a private NSS key with type 'EC'. MOZ_ASSERT(mPrivateKey && mPrivateKey->keyType == ecKey); // The given public key should have the same key type. MOZ_ASSERT(aPublicKey->keyType == mPrivateKey->keyType); nsNSSShutDownPreventionLock locker; ScopedPK11SlotInfo slot(PK11_GetInternalSlot()); if (!slot) { return NS_ERROR_DOM_OPERATION_ERR; } // Generate a random 160-bit object ID. ScopedSECItem objID(::SECITEM_AllocItem(nullptr, nullptr, 20)); SECStatus rv = PK11_GenerateRandomOnSlot(slot, objID->data, objID->len); if (rv != SECSuccess) { return NS_ERROR_DOM_OPERATION_ERR; } // Read EC params. ScopedSECItem params(::SECITEM_AllocItem(nullptr, nullptr, 0)); rv = PK11_ReadRawAttribute(PK11_TypePrivKey, mPrivateKey, CKA_EC_PARAMS, params); if (rv != SECSuccess) { return NS_ERROR_DOM_OPERATION_ERR; } // Read private value. ScopedSECItem value(::SECITEM_AllocItem(nullptr, nullptr, 0)); rv = PK11_ReadRawAttribute(PK11_TypePrivKey, mPrivateKey, CKA_VALUE, value); if (rv != SECSuccess) { return NS_ERROR_DOM_OPERATION_ERR; } SECItem* point = &aPublicKey->u.ec.publicValue; CK_OBJECT_CLASS privateKeyValue = CKO_PRIVATE_KEY; CK_BBOOL falseValue = CK_FALSE; CK_KEY_TYPE ecValue = CKK_EC; CK_ATTRIBUTE keyTemplate[9] = { { CKA_CLASS, &privateKeyValue, sizeof(privateKeyValue) }, { CKA_KEY_TYPE, &ecValue, sizeof(ecValue) }, { CKA_TOKEN, &falseValue, sizeof(falseValue) }, { CKA_SENSITIVE, &falseValue, sizeof(falseValue) }, { CKA_PRIVATE, &falseValue, sizeof(falseValue) }, { CKA_ID, objID->data, objID->len }, { CKA_EC_PARAMS, params->data, params->len }, { CKA_EC_POINT, point->data, point->len }, { CKA_VALUE, value->data, value->len }, }; mPrivateKey = PrivateKeyFromPrivateKeyTemplate(objID, keyTemplate, PR_ARRAY_SIZE(keyTemplate)); NS_ENSURE_TRUE(mPrivateKey, NS_ERROR_DOM_OPERATION_ERR); return NS_OK; }