private static void AddCertificateToList(byte[] storageKey, CertificateHashEntry newCertHashEntry) { CertificateHashMapEntry trustedRootCaHashMapEntry; byte[] newCertHashEntrySerialized = SerializationUtil.Serialize(newCertHashEntry); byte[] trustedRootCAListHashMapEntrySerialized = StorageUtil.readFromStorage(storageKey); if (trustedRootCAListHashMapEntrySerialized == null) { trustedRootCaHashMapEntry = new CertificateHashMapEntry(); trustedRootCaHashMapEntry.certificateHashArray = new byte[1][]; trustedRootCaHashMapEntry.certificateHashArray[0] = newCertHashEntrySerialized; } else { trustedRootCaHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(trustedRootCAListHashMapEntrySerialized); byte[][] newCertificateHashArray = new byte[trustedRootCaHashMapEntry.certificateHashArray.Length + 1][]; newCertificateHashArray[0] = newCertHashEntrySerialized; for (int i = 0; i < trustedRootCaHashMapEntry.certificateHashArray.Length; i++) { newCertificateHashArray[i + 1] = trustedRootCaHashMapEntry.certificateHashArray[i]; } trustedRootCaHashMapEntry.certificateHashArray = newCertificateHashArray; } trustedRootCAListHashMapEntrySerialized = SerializationUtil.Serialize(trustedRootCaHashMapEntry); StorageUtil.saveToStorage(storageKey, trustedRootCAListHashMapEntrySerialized); }
private static void AddFraudToList(byte[] storageKey, byte[] newDraudIdStorageKey) { FraudEntryMapEntry fraudEntryMapEntry; byte[] fraudEntryMapEntrySerialized = StorageUtil.readFromStorage(storageKey); if (fraudEntryMapEntrySerialized == null) { fraudEntryMapEntry = new FraudEntryMapEntry(); fraudEntryMapEntry.fraudEntryArray = new byte[1][]; fraudEntryMapEntry.fraudEntryArray[0] = newDraudIdStorageKey; } else { fraudEntryMapEntry = (FraudEntryMapEntry)SerializationUtil.Deserialize(fraudEntryMapEntrySerialized); byte[][] newFraudEntryArray = new byte[fraudEntryMapEntry.fraudEntryArray.Length + 1][]; newFraudEntryArray[0] = newDraudIdStorageKey; for (int i = 0; i < fraudEntryMapEntry.fraudEntryArray.Length; i++) { newFraudEntryArray[i + 1] = fraudEntryMapEntry.fraudEntryArray[i]; } fraudEntryMapEntry.fraudEntryArray = newFraudEntryArray; } fraudEntryMapEntrySerialized = SerializationUtil.Serialize(fraudEntryMapEntry); StorageUtil.saveToStorage(storageKey, fraudEntryMapEntrySerialized); }
public static void MarkRootCaCertificateUntrustedInStorage(Certificate rootCACertificate, byte[] certificateHash) { byte[] cACertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); CaCertificateEntry cACertificateEntry = (CaCertificateEntry)SerializationUtil.Deserialize(cACertificateEntrySerialized); cACertificateEntry.IsTrusted = false; cACertificateEntrySerialized = SerializationUtil.Serialize(cACertificateEntry); StorageUtil.saveToStorage(certificateHash, cACertificateEntrySerialized); MarkAllCertificatesAsRevokedForCa(rootCACertificate); }
public static FraudEntry ReadFraudEntry(byte[] fraudId) { FraudEntry fraudEntry = new FraudEntry(); byte[] fraudIdStorageKey = ArrayUtil.Concat(FRAUD_ID_STORAGE_PREFIX, fraudId); byte[] fraudEntrySerialized = StorageUtil.readFromStorage(fraudIdStorageKey); if (fraudEntrySerialized == null) { return(fraudEntry); } return((FraudEntry)SerializationUtil.Deserialize(fraudEntrySerialized)); }
public static EndEntityCertificateEntry RetrieveEndEntityCertificateFromStorage(byte[] certificateHash) { byte[] endEntityCertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); if (endEntityCertificateEntrySerialized == null) { Logger.log("Can not find end entity certificate in storage"); return(new EndEntityCertificateEntry()); } EndEntityCertificateEntry entityCertificateEntry = (EndEntityCertificateEntry)SerializationUtil.Deserialize(endEntityCertificateEntrySerialized); return(entityCertificateEntry); }
public static bool MarkSubCaCertificateRevokedInStorage(Certificate subCACertificate, byte[] certificateHash) { byte[] cACertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); CaCertificateEntry cACertificateEntry = (CaCertificateEntry)SerializationUtil.Deserialize(cACertificateEntrySerialized); if (cACertificateEntry.IsRevoked || cACertificateEntry.IsTrusted) { return(false); } cACertificateEntry.IsRevoked = true; cACertificateEntrySerialized = SerializationUtil.Serialize(cACertificateEntry); StorageUtil.saveToStorage(certificateHash, cACertificateEntrySerialized); MarkAllCertificatesAsRevokedForCa(subCACertificate); return(true); }
public static bool MarkEndEntityCertificateRevokedInStorage(byte[] certificateHash) { byte[] endEntityCertificateEntrySerialized = StorageUtil.readFromStorage(certificateHash); if (endEntityCertificateEntrySerialized == null) { Logger.log("Can not find end entity certificate in storage"); return(false); } EndEntityCertificateEntry entityCertificateEntry = (EndEntityCertificateEntry)SerializationUtil.Deserialize(endEntityCertificateEntrySerialized); entityCertificateEntry.IsRevoked = true; endEntityCertificateEntrySerialized = SerializationUtil.Serialize(entityCertificateEntry); StorageUtil.saveToStorage(certificateHash, endEntityCertificateEntrySerialized); return(true); }
public static CertificateHashEntry[] RetrieveCertList(byte[] storageKey) { byte[] trustedRootCAListHashMapEntrySerialized = StorageUtil.readFromStorage(storageKey); if (trustedRootCAListHashMapEntrySerialized == null) { return(new CertificateHashEntry[0]); } else { CertificateHashMapEntry trustedRootCaHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(trustedRootCAListHashMapEntrySerialized); CertificateHashEntry[] retCertificateHashEntries = new CertificateHashEntry[trustedRootCaHashMapEntry.certificateHashArray.Length]; for (int i = 0; i < trustedRootCaHashMapEntry.certificateHashArray.Length; i++) { byte[] certificateHashEntrySerialized = trustedRootCaHashMapEntry.certificateHashArray[i]; CertificateHashEntry certificateHashEntry = (CertificateHashEntry)SerializationUtil.Deserialize(certificateHashEntrySerialized); retCertificateHashEntries[i] = certificateHashEntry; } return(retCertificateHashEntries); } }
public static bool IsSSLCertificateAddedBefore(byte[] certificateHash) { //todo: change to NeoVM implementation for real Smart Contract byte[] value = StorageUtil.readFromStorage(certificateHash); return(value != null); }