protected virtual void runCallback() { onStimuliFetched(); firstStimuliOptions = ArrayUtil.Concat(firstStimuliCategory1Options, firstStimuliCategory2Options); secondStimuliOptions = ArrayUtil.Concat(secondStimuliCategory1Options, secondStimuliCategory2Options); finalFetchCallbackFired = true; }
private static void AddCertificateToCaIssuedCertificateList(Certificate certificate, byte[] certificateHash) { CertificateHashMapEntry certHashMapEntry; byte[] storageKey = ArrayUtil.Concat(ELEMENT_LIST, certificate.AuthorityKeyIdentifier.keyIdentifier); byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(storageKey); if (certHashMapEntrySerialized == null) { certHashMapEntry = new CertificateHashMapEntry(); certHashMapEntry.CertificateHashList = new List <CertificateHashEntry>(); //certHashMapEntry.Count = 0; } else { certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); } CertificateHashEntry newCertHashEntry = new CertificateHashEntry(); newCertHashEntry.CertificateHash = certificateHash; newCertHashEntry.IsCa = certificate.BasicConstraints.IsCa; certHashMapEntry.CertificateHashList.Add(newCertHashEntry); // certHashMapEntry.Count += 1; certHashMapEntrySerialized = SerializationUtil.Serialize(certHashMapEntry); StorageUtil.saveToStorage(storageKey, certHashMapEntrySerialized); }
// port of PHPass crypt_private function (http://www.openwall.com/phpass/) private bool CheckPHPassPassword(string password, string hash) { MD5 md5 = MD5.Create(); Encoding encoding = Encoding.UTF8; int count_log2 = itoa64.IndexOf(hash[3]); int count = 1 << count_log2; string salt = hash.Substring(4, 8); if (salt.Length != 8) { return(false); } byte[] tmpHash = md5.ComputeHash(encoding.GetBytes(salt + password)); byte[] password_bytes = encoding.GetBytes(password); do { tmpHash = md5.ComputeHash(ArrayUtil.Concat <byte>(tmpHash, password_bytes)); } while(--count > 0); string output = hash.Substring(0, 12); output += encode64(tmpHash, 16); return(hash == output); }
private string GetRootedPath(string path) { if (_keyRootParts == null || !_keyRootParts.Any()) { return(path); } return(string.Join(_config.Delimiter, ArrayUtil.Concat(_keyRootParts, new[] { path }))); }
public static byte[] generateUntrustRootCAOperationRequestSignature(byte[] rootCertBytes) { ISigner signer = SignerUtilities.GetSigner("SHA-256withECDSA"); byte[] dataForSign = ArrayUtil.Concat(OPERATION_UNTRUST_ROOT_CA_CERTIFICATE, rootCertBytes); signer.Init(true, decodePrivateKeyParameter(ROOT_CA_REQUEST_SIGNATURE_PKCS8_PRIVATE_KEY)); signer.BlockUpdate(dataForSign, 0, dataForSign.Length); return(signer.GenerateSignature()); }
internal static Type CreateDelegateType(TypeWrapper tw, MethodWrapper mw) { TypeWrapper[] args = mw.GetParameters(); if (!mw.IsStatic) { args = ArrayUtil.Concat(tw, args); } return(CreateDelegateType(args, mw.ReturnType)); }
public static byte[] generateRevokeSSLCertificateOperationRequestSignature(string signAlg, byte[] encodedCertificateBytes, string pkcs8FilePath) { ISigner signer = SignerUtilities.GetSigner(signAlg); byte[] dataForSign = ArrayUtil.Concat(OPERATION_REVOKE_SSL_CERTIFICATE, encodedCertificateBytes); signer.Init(true, readPrivateKeyFromP8File(pkcs8FilePath)); signer.BlockUpdate(dataForSign, 0, dataForSign.Length); return(signer.GenerateSignature()); }
public void AddRequiredActivationAuras(params Spell[] spells) { if (RequiredActivationAuras == null) { RequiredActivationAuras = spells; } else { ArrayUtil.Concat(ref RequiredActivationAuras, spells); } }
private static TypeWrapper[] GetImplParameters(ClassFile.ConstantPoolItemMethodHandle implMethod) { MethodWrapper mw = (MethodWrapper)implMethod.Member; TypeWrapper[] parameters = mw.GetParameters(); if (mw.IsStatic || mw.IsConstructor) { return(parameters); } return(ArrayUtil.Concat(mw.DeclaringType, parameters)); }
internal void Add(int instructionIndex) { if (data == null) { data = new int[] { instructionIndex }; } else { data = ArrayUtil.Concat(data, instructionIndex); } }
private static void ArrayAppend <T>(ref T[] array, T element) { if (array == null) { array = new T[] { element }; } else { array = ArrayUtil.Concat(array, element); } }
public void Merge(Identifications other) { if (type != other.type) { throw new Exception("Different types."); } scanNumbers = ArrayUtil.Concat(scanNumbers, other.scanNumbers); peptides = ArrayUtil.Concat(peptides, other.peptides); fixedModifications = ArrayUtil.Concat(fixedModifications, other.fixedModifications); int[] o = ArrayUtil.Order(scanNumbers); scanNumbers = ArrayUtil.SubArray(scanNumbers, o); peptides = ArrayUtil.SubArray(peptides, o); fixedModifications = ArrayUtil.SubArray(fixedModifications, o); }
private void PageChanged(DateTime eventTime, PageBE page, UserBE user, XDoc extra, params string[] path) { try { XUri channel = _channel.At(PAGES).At(path); XUri resource = PageBL.GetUriCanonical(page).WithHost(_wikiid); string[] origin = new string[] { PageBL.GetUriCanonical(page).AsServerUri().ToString(), XUri.Localhost + "/" + page.Title.AsUiUriPath() }; XDoc doc = new XDoc("deki-event") .Elem("channel", channel) // BUGBUGBUG: This will generally generate a Uri based on the request that caused the event, // which may not really be canonical .Elem("uri", PageBL.GetUriCanonical(page).AsPublicUri().ToString()) .Elem("pageid", page.ID) .Start("user") .Attr("id", user.ID) .Attr("anonymous", UserBL.IsAnonymous(user)) .Elem("uri", UserBL.GetUri(user)) .End() .Start("content.uri") .Attr("type", "application/xml") .Value(PageBL.GetUriContentsCanonical(page).With("format", "xhtml").AsServerUri().ToString()) .End() .Elem("revision.uri", PageBL.GetUriRevisionCanonical(page).AsServerUri().ToString()) .Elem("tags.uri", PageBL.GetUriCanonical(page).At("tags").AsServerUri().ToString()) .Elem("comments.uri", PageBL.GetUriCanonical(page).At("comments").AsServerUri().ToString()) .Elem("path", page.Title.AsUiUriPath()); if (extra != null) { doc.Add(extra); } Queue(eventTime, channel, resource, origin, doc); if (page.Title.IsTalk) { PageBE front = PageBL.GetPageByTitle(page.Title.AsFront()); if ((front != null) && (front.ID > 0)) { PageChanged(eventTime, front, user, extra, ArrayUtil.Concat(new string[] { DEPENDENTS_CHANGED, TALK }, path)); } } } catch (Exception e) { _log.WarnExceptionMethodCall(e, "PageChanged", "event couldn't be created"); } }
public void Write_100_bytes_100_times_Read_10000_bytes() { byte[] bytes = GetBytes(100); byte[][] arrays = new byte[100][]; var stream = new ChunkedMemoryStream(); for (int i = 0; i < 100; ++i) { stream.Write(bytes, 0, bytes.Length); arrays[i] = bytes; } stream.Position = 0; byte[] buffer = new byte[100 * bytes.Length]; int read = stream.Read(buffer, 0, buffer.Length); Assert.AreEqual(buffer.Length, read); Assert.AreEqual(ArrayUtil.Concat(arrays), buffer); Assert.AreEqual(0, stream.Read(buffer, 0, buffer.Length)); }
protected override void Apply(WorldObject target, ref DamageAction[] actions) { try { if (this.Cast == null || this.Cast.CasterUnit == null || target == null) { return; } int length = this.Effect.MiscValueB; if (length == 0 && this.Effect.MiscValue > 0) { length = 1; } DamageAction[] values = new DamageAction[length]; for (int index = 0; index < length; ++index) { values[index] = ((Unit)target).DealSpellDamage(this.m_cast.CasterUnit, this.Effect, this.CalcPrcBoostDamageValue(), true, true, false, false); if (this.Effect.Spell.RealId == (short)709) { float hp = MathUtil.ClampMinMax((float)values[index].ActualDamage * 0.7f, 0.0f, (float)this.Cast.CasterUnit.MaxHealth * 0.3f); this.Cast.CasterUnit.Map.CallDelayed((int)this.Effect.Spell.CastDelay + 200, (Action)(() => this.Cast.CasterUnit.Heal((int)hp, (Unit)null, (SpellEffect)null))); } } if (actions == null) { actions = values; } else { ArrayUtil.Concat <DamageAction>(ref actions, values); } } catch (NullReferenceException ex) { } }
protected override void Apply(WorldObject target, ref DamageAction[] actions) { try { if (Cast == null || Cast.CasterUnit == null || target == null) { return; } var hits = Effect.MiscValueB; if (hits == 0 && Effect.MiscValue > 0) { hits = 1; } var acs = new DamageAction[hits]; for (int i = 0; i < hits; i++) { acs[i] = ((Unit)target).DealSpellDamage(m_cast.CasterUnit, Effect, CalcPrcBoostDamageValue(), true, true, false, false); if (Effect.Spell.RealId == 709)//StealLife { var hp = MathUtil.ClampMinMax(acs[i].ActualDamage * 0.7f, 0, Cast.CasterUnit.MaxHealth * 0.3f); Cast.CasterUnit.Map.CallDelayed((int)(Effect.Spell.CastDelay + 200), () => Cast.CasterUnit.Heal((int)hp)); } } if (actions == null) { actions = acs; } else { ArrayUtil.Concat(ref actions, acs); } } catch (NullReferenceException) { } }
private static void MarkAllCertificatesAsRevokedForCa(Certificate caCertificate) { byte[] storageKey = ArrayUtil.Concat(ELEMENT_LIST, caCertificate.SubjectKeyIdentifier.keyIdentifier); byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(storageKey); if (certHashMapEntrySerialized == null) { return; } CertificateHashMapEntry certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); foreach (var certificateHashEntry in certHashMapEntry.CertificateHashList) { if (certificateHashEntry.IsCa) { MarkSubCaCertificateRevokedInStore(certificateHashEntry.CertificateHash); } else { MarkEndEntityCertificateRevokedInStore(certificateHashEntry.CertificateHash); } } }
private static Type CreateDelegateType(Type[] types, Type retType) { if (types.Length == 0 && retType == Types.Void) { return(typeofMHV[0]); } else if (types.Length > MaxArity) { int arity = types.Length; int remainder = (arity - 8) % 7; int count = (arity - 8) / 7; if (remainder == 0) { remainder = 7; count--; } Type last = typeofMHA.MakeGenericType(SubArray(types, types.Length - 8, 8)); for (int i = 0; i < count; i++) { Type[] temp = SubArray(types, types.Length - 8 - 7 * (i + 1), 8); temp[7] = last; last = typeofMHA.MakeGenericType(temp); } types = SubArray(types, 0, remainder + 1); types[remainder] = last; } if (retType == Types.Void) { return(typeofMHV[types.Length].MakeGenericType(types)); } else { types = ArrayUtil.Concat(types, retType); return(typeofMH[types.Length].MakeGenericType(types)); } }
private void Add2(int i, int j) { int d = j - i; if (neighborListMultiple.ContainsKey(i)) { int[] w = neighborListMultiple[i]; int[] w2 = ArrayUtil.Concat(w, d); neighborListMultiple.Remove(i); neighborListMultiple.Add(i, w2); return; } if (neighborListSingle.ContainsKey(i)) { int w = neighborListSingle[i]; int[] w2 = new int[] { w, d }; neighborListSingle.Remove(i); neighborListMultiple.Add(i, w2); return; } neighborListSingle.Add(i, d); }
public void Should_Add_SSL_Certificate() { { string rootCertFilePath = "../../../test-data/certs/test-ca/Test-Root-CA-RSA-2048.cer"; byte[] rootCertEncoded = File.ReadAllBytes(rootCertFilePath); byte[] rootCertDigest = DigestUtilities.CalculateDigest("SHA_256", rootCertEncoded); byte[] requestSignature = SignUtil.generateAddTrustedRootCAOperationRequestSignature(rootCertEncoded); bool result = RootCaCertificateHandler.AddTrustedRootCaCertificate(rootCertDigest, rootCertEncoded, requestSignature); Assert.True(result); } { string subCaCertFilePath = "../../../test-data/certs/test-ca/Test-Sub-CA-RSA-2048.cer"; byte[] subCaCertEncoded = File.ReadAllBytes(subCaCertFilePath); byte[] subCaCertificateHash = DigestUtilities.CalculateDigest("SHA_256", subCaCertEncoded); byte[] subCaAddRequestSignature = null; bool result = SubCaCertificateHandler.AddSubCaCertificate(subCaCertificateHash, subCaCertEncoded, subCaAddRequestSignature); Assert.True(result); } string sSLCertFilePath = "../../../test-data/certs/test-ca/Test-SSL-RSA-2048.cer"; byte[] sSLCertEncoded = File.ReadAllBytes(sSLCertFilePath); byte[] sSLCertHash = DigestUtilities.CalculateDigest("SHA_256", sSLCertEncoded); bool sslCertAddResult = SslCertificateHandler.AddSslCertificate(sSLCertHash, sSLCertEncoded); Assert.True(sslCertAddResult); Certificate sslCertificate = CertificateParser.Parse(sSLCertEncoded); byte[] sSLCertificateEntryByte = StorageUtil.readFromStorage(sSLCertHash); EndEntityCertificateEntry sSLCertificateEntry = (EndEntityCertificateEntry)SerializationUtil.Deserialize(sSLCertificateEntryByte); Assert.False(sSLCertificateEntry.IsRevoked); Assert.Equal(sSLCertificateEntry.CertificateValue, sSLCertEncoded); //Is Added To Issuer list { byte[] storageKey = ArrayUtil.Concat(CertificateStorageManager.ELEMENT_LIST, sslCertificate.AuthorityKeyIdentifier.keyIdentifier); byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(storageKey); Assert.True(certHashMapEntrySerialized != null); CertificateHashMapEntry certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); Assert.True(certHashMapEntry.certificateHashArray != null); Assert.True(certHashMapEntry.certificateHashArray.Length == 1); byte[] subjectKeyIdCertificateHashEntrySerialized = certHashMapEntry.certificateHashArray[0]; CertificateHashEntry subjectKeyIdCertificateHashEntry = (CertificateHashEntry)SerializationUtil.Deserialize(subjectKeyIdCertificateHashEntrySerialized); Assert.Equal(subjectKeyIdCertificateHashEntry.CertificateHash, sSLCertHash); Assert.False(subjectKeyIdCertificateHashEntry.IsCa); } //Domain Name List - Common Name { byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(HexUtil.HexStringToByteArray("6f6e742e696f")); Assert.True(certHashMapEntrySerialized != null); CertificateHashMapEntry certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); Assert.True(certHashMapEntry.certificateHashArray != null); Assert.True(certHashMapEntry.certificateHashArray.Length == 1); byte[] subjectKeyIdCertificateHashEntrySerialized = certHashMapEntry.certificateHashArray[0]; CertificateHashEntry subjectKeyIdCertificateHashEntry = (CertificateHashEntry)SerializationUtil.Deserialize(subjectKeyIdCertificateHashEntrySerialized); Assert.Equal(subjectKeyIdCertificateHashEntry.CertificateHash, sSLCertHash); Assert.False(subjectKeyIdCertificateHashEntry.IsCa); } //Domain Name List - Subject Alternative Name { byte[] certHashMapEntrySerialized = StorageUtil.readFromStorage(HexUtil.HexStringToByteArray("7777772e6f6e742e696f")); Assert.True(certHashMapEntrySerialized != null); CertificateHashMapEntry certHashMapEntry = (CertificateHashMapEntry)SerializationUtil.Deserialize(certHashMapEntrySerialized); Assert.True(certHashMapEntry.certificateHashArray != null); Assert.True(certHashMapEntry.certificateHashArray.Length == 1); byte[] subjectKeyIdCertificateHashEntrySerialized = certHashMapEntry.certificateHashArray[0]; CertificateHashEntry subjectKeyIdCertificateHashEntry = (CertificateHashEntry)SerializationUtil.Deserialize(subjectKeyIdCertificateHashEntrySerialized); Assert.Equal(subjectKeyIdCertificateHashEntry.CertificateHash, sSLCertHash); Assert.False(subjectKeyIdCertificateHashEntry.IsCa); } }
private void UserDependentChanged(DateTime eventTime, UserBE user, params string[] path) { UserChanged(eventTime, user, ArrayUtil.Concat(new string[] { DEPENDENTS_CHANGED }, path)); }
private void PageDependentChanged(DateTime eventTime, PageBE page, UserBE user, params string[] path) { PageChanged(eventTime, page, user, null, ArrayUtil.Concat(new string[] { DEPENDENTS_CHANGED }, path)); }
/// <summary> /// Creates an RFC 6455 BFP frame with the opcode and payload bytes specified. /// </summary> /// <param name="opCode">BFP opcode.</param> /// <param name="isMasked">Boolean indicating whether to mask the payload.</param> /// <param name="payLoad">Payload bytes.</param> /// <returns></returns> public static WSFrame CreateFrame(WSFrameType opCode, bool isMasked, byte[] payLoad) { // TODO - add code to support continuation frames // - add long maxFrameLength parameter // - return array of WSFrame objects byte controlByte0 = (byte)(0x80 | (byte)opCode); byte controlByte1 = (isMasked && payLoad != null && payLoad.Length > 0 ? (byte)0x80 : (byte)0x00); byte[] mask = (isMasked ? CryptoUtils.GetRandomBytes(4) : new byte[0]); int maskIndex = 0; Int32 payloadIndex = 0; UInt16 length16 = 0; UInt32 length32 = 0; UInt64 length64 = 0; byte[] frameData = null; if (payLoad == null || payLoad.Length == 0) { length32 = 0; payloadIndex = 0; frameData = ArrayUtil.Concat(controlByte0, controlByte1); } else if (payLoad.Length <= 125) { controlByte1 = (byte)(controlByte1 | (byte)payLoad.Length); length32 = (UInt32)payLoad.Length; maskIndex = (isMasked ? 2 : 0); payloadIndex = (isMasked ? 6 : 2); frameData = ArrayUtil.Concat(controlByte0, controlByte1, mask, payLoad); } else if (payLoad.Length <= UInt16.MaxValue) { controlByte1 = (byte)(controlByte1 | (byte)126); length16 = (UInt16)payLoad.Length; length32 = length16; maskIndex = (isMasked ? 4 : 0); payloadIndex = (isMasked ? 8 : 4); frameData = ArrayUtil.Concat(controlByte0, controlByte1, length16, mask, payLoad); } else { controlByte1 = (byte)(controlByte1 | (byte)127); length32 = (UInt32)payLoad.Length; length64 = (UInt64)payLoad.Length; maskIndex = (isMasked ? 10 : 0); payloadIndex = (isMasked ? 14 : 10); frameData = ArrayUtil.Concat(controlByte0, controlByte1, length64, mask, payLoad); } WSFrame dataFrame = new WSFrame() { maskIndex = maskIndex, payloadIndex = payloadIndex, payloadLength = (Int32)length32, frameData = frameData }; if (isMasked) { // Logger.WriteDebug("wsframe", string.Concat("raw: ", frameData.ToHex())); ApplyMask(dataFrame); } return(dataFrame); }
public static string[] RootedPath(this AwsS3ClientConfig config, params string[] path) { return(ArrayUtil.Concat(new[] { config.Bucket }, config.RootPath.Split('/'), path)); }
private static Byte[] EncodeDerTag(Byte tclass, Boolean tconstructed, Int32 tnumber, params Byte[][] values) { Byte[] value = values == null ? new Byte[0] : ArrayUtil.Concat(values); using (MemoryStream ms = new MemoryStream()) { if (tnumber <= 30) { ms.WriteByte((Byte)(((tclass & 3) << 6) | (tconstructed ? 0x20 : 0x00) | (tnumber & 0x1F))); } else { ms.WriteByte((Byte)(((tclass & 3) << 6) | (tconstructed ? 0x20 : 0x00) | 0x31)); if (tnumber > 0xFE00000) { ms.WriteByte((Byte)(0x80 | ((tnumber >> 28) & 0x7F))); } if (tnumber > 0x1FC000) { ms.WriteByte((Byte)(0x80 | ((tnumber >> 21) & 0x7F))); } if (tnumber > 0x3F80) { ms.WriteByte((Byte)(0x80 | ((tnumber >> 14) & 0x7F))); } if (tnumber > 0x7F) { ms.WriteByte((Byte)(0x80 | ((tnumber >> 7) & 0x7F))); } ms.WriteByte((Byte)(tnumber & 0x7F)); } if (value.Length < 0x80) { ms.WriteByte((Byte)value.Length); } else if (value.Length < 0x100) { ms.WriteByte(0x81); ms.WriteByte((Byte)value.Length); } else if (value.Length < 0x10000) { ms.WriteByte(0x82); ms.WriteByte((Byte)(value.Length >> 8)); ms.WriteByte((Byte)value.Length); } else if (value.Length < 0x1000000) { ms.WriteByte(0x83); ms.WriteByte((Byte)(value.Length >> 16)); ms.WriteByte((Byte)(value.Length >> 8)); ms.WriteByte((Byte)value.Length); } else { ms.WriteByte(0x84); ms.WriteByte((Byte)(value.Length >> 24)); ms.WriteByte((Byte)(value.Length >> 16)); ms.WriteByte((Byte)(value.Length >> 8)); ms.WriteByte((Byte)value.Length); } ms.Write(value, 0, value.Length); return(ms.ToArray()); } }
public static Byte[] GenerateCertificateSigningRequest(RSACryptoServiceProvider key, params String[] domains) { RSAParameters key_params = key.ExportParameters(false); Byte[] csr = EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x02, new Byte[] { 0x00 }), //INTEGER version: 0 EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x11, //SET EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x55, 0x04, 0x03 }), //OBJECT: commonName EncodeDerTag(0, false, 0x0C, Encoding.UTF8.GetBytes(domains[0])) //UTF8STRING ) ) ), EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 }), //OBJECT: rsaEncryption EncodeDerTag(0, false, 0x05) //NULL ), EncodeDerTag(0, false, 0x03, //BIT STRING new Byte[1] { 0 }, //Number of unused bits in final octet EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x02, ArrayUtil.Concat(new Byte[] { 0 }, key_params.Modulus)), //INTEGER - Don't know why we need the extra zero, but it seems necessary for the CSR to be accepted. EncodeDerTag(0, false, 0x02, key_params.Exponent) //INTEGER ) ) ), EncodeDerTag(2, true, 0x00, //cont[0] EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x09, 0x0E }), //OBJECT: Extension Request EncodeDerTag(0, true, 0x11, //SET EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x55, 0x1D, 0x11 }), //OBJECT: X509v3 Subject Alternative Name EncodeDerTag(0, false, 0x04, //OCTET STRING EncodeDerTag(0, true, 0x10, //SEQUENCE Array.ConvertAll(domains, domain => EncodeDerTag(2, false, 0x02, Encoding.UTF8.GetBytes(domain))) //DNS name ) ) ) ) ) ) ) ); Byte[] signature; using (SHA256 sha = SHA256.Create()) signature = key.SignData(csr, sha); csr = EncodeDerTag(0, true, 0x10, //SEQUENCE csr, EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B }), //OBJECT: sha256WithRSAEncryption EncodeDerTag(0, false, 0x05) //NULL ), EncodeDerTag(0, false, 0x03, //BIT STRING new Byte[1] { 0 }, //Number of unused bits in final octet signature ) ); return(csr); }
protected override void runCallback() { base.runCallback(); firstStimuliOptions = ArrayUtil.Concat(sprites[0][0], sprites[0][1]); secondStimuliOptions = ArrayUtil.Concat(sprites[1][0], sprites[1][1]); }
private void PropertyChanged(DateTime eventTime, ResourceBE prop, UserBE user, ResourceBE.ParentType parentType, XUri parentUri, params string[] path) { try { string parent = string.Empty; switch (parentType) { case ResourceBE.ParentType.PAGE: parent = PAGES; break; case ResourceBE.ParentType.FILE: parent = FILES; break; case ResourceBE.ParentType.USER: parent = USERS; break; case ResourceBE.ParentType.SITE: parent = SITE; break; } XUri channel = _channel.At(parent).At(PROPERTY).At(path); XUri resource = prop.PropertyInfoUri(parentUri); string[] origin = new string[] { resource.ToString() }; XDoc doc = new XDoc("deki-event") .Elem("channel", channel) .Elem("name", prop.Name) .Elem("uri", resource) .Start("content") .Attr("mime-type", prop.MimeType.FullType) .Attr("size", prop.Size) .Attr("href", prop.PropertyContentUri(parentUri)); if (prop.MimeType.MainType == MimeType.TEXT.MainType && prop.Size < 256) { doc.Value(ResourceContentBL.Instance.Get(prop).ToText()); } doc.End(); if (parentType == ResourceBE.ParentType.PAGE) { doc.Elem("pageid", prop.ParentPageId ?? 0); } else if (parentType == ResourceBE.ParentType.USER) { doc.Elem("userid", prop.ParentUserId ?? 0); } else if (parentType == ResourceBE.ParentType.FILE) { ResourceBE attachment = ResourceBL.Instance.GetResource(prop.ParentId.Value); doc.Elem("fileid", attachment.MetaXml.FileId ?? 0); PageDependentChanged(eventTime, PageBL.GetPageById(attachment.ParentPageId.Value), user, ArrayUtil.Concat(new string[] { FILES, PROPERTY }, path)); } Queue(eventTime, channel, resource, origin, doc); } catch (Exception e) { _log.WarnExceptionMethodCall(e, "PropertyChanged", "event couldn't be created"); } }
public void PageMessage(DateTime eventTime, PageBE page, UserBE user, XDoc body, string[] path) { PageChanged(eventTime, page, user, body, ArrayUtil.Concat(new string[] { MESSAGE }, path)); }
public static X509Certificate2 GenerateSelfSignedCertificate(RSACryptoServiceProvider key, params String[] domains) { RSAParameters key_params = key.ExportParameters(false); DateTime notBefore = DateTime.Now.AddMonths(-1); DateTime notAfter = DateTime.Now.AddYears(10); Byte[] cert = EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(2, true, 0x00, //cont[0] EncodeDerTag(0, false, 0x02, new Byte[] { 2 }) //INTEGER version: 2 ), EncodeDerTag(0, false, 0x02, new Byte[] { 1 }, UCIS.NaCl.randombytes.generate(16)), //INTEGER serial EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B }), //OBJECT: sha256WithRSAEncryption EncodeDerTag(0, false, 0x05) //NULL ), EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x11, //SET EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x55, 0x04, 0x03 }), EncodeDerTag(0, false, 0x0C, Encoding.UTF8.GetBytes(domains[0])) ) ) ), EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x17, Encoding.ASCII.GetBytes(notBefore.ToString("yyMMddHHmmss\\Z"))), //UTCTIME notbefore EncodeDerTag(0, false, 0x17, Encoding.ASCII.GetBytes(notAfter.ToString("yyMMddHHmmss\\Z"))) //UTCTIME notafter ), EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x11, //SET EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x55, 0x04, 0x03 }), //OBJECT: commonName EncodeDerTag(0, false, 0x0C, Encoding.UTF8.GetBytes(domains[0])) //UTF8STRING ) ) ), EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01 }), EncodeDerTag(0, false, 0x05) //NULL ), EncodeDerTag(0, false, 0x03, //BIT STRING new Byte[1] { 0 }, //Number of unused bits in final octet EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x02, ArrayUtil.Concat(new Byte[] { 0 }, key_params.Modulus)), //INTEGER - Don't know why we need the extra zero, but it seems necessary for the CSR to be accepted. EncodeDerTag(0, false, 0x02, key_params.Exponent) //INTEGER ) ) ), EncodeDerTag(2, true, 0x03, //cont[0] EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x55, 0x1D, 0x11 }), //OBJECT: X509v3 Subject Alternative Name EncodeDerTag(0, false, 0x04, //OCTET STRING EncodeDerTag(0, true, 0x10, //SEQUENCE Array.ConvertAll(domains, domain => EncodeDerTag(2, false, 0x02, Encoding.UTF8.GetBytes(domain))) //DNS name ) ) ) ) ) ); Byte[] signature; using (SHA256 sha = SHA256.Create()) signature = key.SignData(cert, sha); cert = EncodeDerTag(0, true, 0x10, //SEQUENCE cert, EncodeDerTag(0, true, 0x10, //SEQUENCE EncodeDerTag(0, false, 0x06, new Byte[] { 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x0B }), //OBJECT: sha256WithRSAEncryption EncodeDerTag(0, false, 0x05) //NULL ), EncodeDerTag(0, false, 0x03, //BIT STRING new Byte[1] { 0 }, //Number of unused bits in final octet signature ) ); X509Certificate2 c = new X509Certificate2(cert); c.PrivateKey = key; return(c); }