示例#1
0
        public PrivilegedAttributeCertificate(KrbAuthorizationData authz, SignatureMode mode = SignatureMode.Kdc)
            : base(authz?.Type ?? 0, AuthorizationDataType.AdWin2kPac)
        {
            var pac = authz.Data;

            this.pacData = new byte[pac.Length];
            this.Mode    = mode;

            pac.CopyTo(this.pacData);

            using (var stream = new NdrBuffer(pac, align: false))
            {
                var count = stream.ReadInt32LittleEndian();

                this.Version = stream.ReadInt32LittleEndian();

                if (this.Version != PAC_VERSION)
                {
                    throw new InvalidDataException($"Unknown PAC Version {this.Version}");
                }

                var errors = new List <PacDecodeError>();

                for (var i = 0; i < count; i++)
                {
                    var type = (PacType)stream.ReadInt32LittleEndian();
                    var size = stream.ReadInt32LittleEndian();

                    var offset = stream.ReadInt64LittleEndian();

                    var pacInfoBuffer = pac.Slice((int)offset, size);

                    int exclusionStart;
                    int exclusionLength;

                    try
                    {
                        this.ParsePacType(type, pacInfoBuffer, out exclusionStart, out exclusionLength);
                    }
                    catch (Exception ex)
                    {
                        errors.Add(new PacDecodeError()
                        {
                            Type      = type,
                            Data      = pacInfoBuffer,
                            Exception = ex
                        });

                        throw;
                    }

                    if (exclusionStart > 0 && exclusionLength > 0)
                    {
                        this.pacData.Span.Slice((int)offset + exclusionStart, exclusionLength).Clear();
                    }
                }

                this.DecodingErrors = errors;
            }
        }
        // ------------------------------------------------------------------

        /*
         *      /// <summary>
         *      /// Initializes a new instance of the
         *      /// <see cref="SimplePatternSignatureChecker"/> class.
         *      /// </summary>
         *      /// <param name="signature">The signature.</param>
         *      /// <param name="signatureMode">The signature mode.</param>
         *      public SimplePatternSignatureChecker(
         *              string signature,
         *              SignatureMode signatureMode )
         *      {
         *              if ( signatureMode == SignatureMode.HexString )
         *              {
         *                      _pattern = ConvertHexStringToBytes( signature );
         *              }
         *              else
         *              {
         *                      _pattern = ConvertTextStringToBytes( signature );
         *              }
         *  _byteoffset = 0;
         *      }*/

        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="SimplePatternSignatureChecker"/> class.
        /// </summary>
        /// <param name="signature">The signature.</param>
        /// <param name="signatureMode">The signature mode.</param>
        public SimplePatternSignatureChecker(
            int byteoffset,
            int firstnumberofbytestoread,
            string signature,
            SignatureMode signatureMode
            )
        {
            if (signatureMode == SignatureMode.HexString)
            {
                _pattern = ConvertHexStringToBytes(signature);
            }
            else
            {
                _pattern = ConvertTextStringToBytes(signature);
            }
            _byteoffset = byteoffset;
            if (firstnumberofbytestoread <= 0)
            {
                _firstnumberofbytestoread = Math.Max(100, (_pattern.Length + _byteoffset));
            }
            else
            {
                _firstnumberofbytestoread = firstnumberofbytestoread;
            }
        }
示例#3
0
        private string GetSignature(MethodDefinition method, SignatureMode mode)
        {
            var text = new StringBuilder();

            text.Append(PrettyType(method.ReturnType));

            if (mode == SignatureMode.Verbose)
            {
                text.Append(" (");
            }
            else if (mode == SignatureMode.Delegate)
            {
                text.Append(" InternalDelegate(");
            }

            for (var i = 0; i < method.Parameters.Count; i++)
            {
                var parameter = method.Parameters[i];
                if (i > 0)
                {
                    if (mode != SignatureMode.Name)
                    {
                        text.Append(", ");
                    }
                }

                if (mode == SignatureMode.Name)
                {
                    text.Append("_");
                }

                text.Append(PrettyType(parameter.ParameterType));

                if (mode == SignatureMode.Delegate)
                {
                    text.Append($" arg{i}");
                }

                if (parameter.IsOptional)
                {
                    if (mode == SignatureMode.Verbose)
                    {
                        text.Append(" = ...");
                    }
                    else if (mode == SignatureMode.Name)
                    {
                        text.Append("___Opt");
                    }
                }

                // TODO: Handle params
            }

            if (mode != SignatureMode.Name)
            {
                text.Append(")");
            }

            return(text.ToString());
        }
示例#4
0
        public SignatureResult Sign(GpgmeData plain, GpgmeData sig, SignatureMode mode)
        {
            EnsureValid();
            if (plain == null)
            {
                throw new ArgumentNullException(nameof(plain), "Source data buffer must be supplied.");
            }
            if (!(plain.IsValid))
            {
                throw new InvalidDataBufferException("The specified source data buffer is invalid.");
            }

            if (sig == null)
            {
                throw new ArgumentNullException(nameof(sig), "Destination data buffer must be supplied.");
            }
            if (!(sig.IsValid))
            {
                throw new InvalidDataBufferException("The specified destination data buffer is invalid.");
            }

            lock (CtxLock) {
                int err = libgpgme.NativeMethods.gpgme_op_sign(
                    CtxPtr,
                    plain.dataPtr,
                    sig.dataPtr,
                    (gpgme_sig_mode_t)mode);

                gpg_err_code_t errcode = libgpgerror.gpg_err_code(err);
                switch (errcode)
                {
                case gpg_err_code_t.GPG_ERR_NO_ERROR:
                    break;

                case gpg_err_code_t.GPG_ERR_UNUSABLE_SECKEY:
                    throw new InvalidKeyException(
                              "There is one or more invalid signing key(s) in the current context.");

                case gpg_err_code_t.GPG_ERR_INV_VALUE:
                    throw new InvalidPtrException(
                              "Either the context, plain text or cipher text pointer is invalid.");

                default:
                    throw GpgmeError.CreateException(errcode);
                }
                IntPtr rst_ptr = libgpgme.NativeMethods.gpgme_op_sign_result(CtxPtr);
                if (rst_ptr != IntPtr.Zero)
                {
                    var sig_rst = new SignatureResult(rst_ptr);
                    return(sig_rst);
                }
                throw new GeneralErrorException("An unexpected error occurred. " + errcode.ToString());
            }
        }
示例#5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HeaderSignature"/> class.
 /// </summary>
 /// <param name="hexStringSignature">The hex string signature.</param>
 /// <param name="signatureName">Name of the signature.</param>
 /// <param name="fileExtensions">The file extensions.</param>
 /// <param name="prohibitionMode">The prohibition mode.</param>
 /// <param name="signatureMode">The signature mode.</param>
 public HeaderSignature(
     string hexStringSignature,
     string signatureName,
     string[] fileExtensions,
     ProhibitionMode prohibitionMode,
     SignatureMode signatureMode)
 {
     _checker = new SimplePatternSignatureChecker(0, 0,
                                                  hexStringSignature,
                                                  signatureMode);
     _signatureName   = signatureName;
     _fileExtensions  = fileExtensions;
     _prohibitionMode = prohibitionMode;
     _byteoffset      = 0;
 }
        private void UpdateFromMem(IntPtr sigPtr)
        {
            _gpgme_new_signature newsig = new _gpgme_new_signature();

            Marshal.PtrToStructure(sigPtr, newsig);

            type        = (SignatureMode)newsig.type;
            pubkey_algo = (KeyAlgorithm)newsig.pubkey_algo;
            hash_algo   = (HashAlgorithm)newsig.hash_algo;
            fpr         = Gpgme.PtrToStringUTF8(newsig.fpr);
            sig_class   = (long)newsig.sig_class;
            timestamp   = (long)newsig.timestamp;

            if (!newsig.next.Equals(IntPtr.Zero))
            {
                next = new NewSignature(newsig.next);
            }
        }
示例#7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HeaderSignature"/> class.
 /// </summary>
 /// <param name="hexStringSignature">The hex string signature.</param>
 /// <param name="signatureName">Name of the signature.</param>
 /// <param name="fileExtensions">The file extensions.</param>
 /// <param name="prohibitionMode">The prohibition mode.</param>
 /// <param name="signatureMode">The signature mode.</param>
 public HeaderSignature(
     int byteoffset,
     int firstnumberofbytestoread,
     string hexStringSignature,
     string signatureName,
     string[] fileExtensions,
     ProhibitionMode prohibitionMode,
     SignatureMode signatureMode)
 {
     _checker = new SimplePatternSignatureChecker(
         byteoffset,
         firstnumberofbytestoread,
         hexStringSignature,
         signatureMode);
     _signatureName   = signatureName;
     _fileExtensions  = fileExtensions;
     _prohibitionMode = prohibitionMode;
     _byteoffset      = byteoffset;
 }
示例#8
0
 private SignatureHelper(SignatureMode signatureMode)
 {
     _signatureMode = signatureMode;
 }
示例#9
0
 /// <summary>
 /// Gets the hash code
 /// </summary>
 /// <returns>Hash code</returns>
 public override int GetHashCode()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hashCode = 41;
         if (FileId != null)
         {
             hashCode = hashCode * 59 + FileId.GetHashCode();
         }
         if (CertificateData != null)
         {
             hashCode = hashCode * 59 + CertificateData.GetHashCode();
         }
         if (CertificatePassword != null)
         {
             hashCode = hashCode * 59 + CertificatePassword.GetHashCode();
         }
         hashCode = hashCode * 59 + SignatureMode.GetHashCode();
         hashCode = hashCode * 59 + SignatureCertificationLevel.GetHashCode();
         hashCode = hashCode * 59 + SignatureHashAlgorithm.GetHashCode();
         if (SignerName != null)
         {
             hashCode = hashCode * 59 + SignerName.GetHashCode();
         }
         if (Reason != null)
         {
             hashCode = hashCode * 59 + Reason.GetHashCode();
         }
         if (Location != null)
         {
             hashCode = hashCode * 59 + Location.GetHashCode();
         }
         if (ContactInfo != null)
         {
             hashCode = hashCode * 59 + ContactInfo.GetHashCode();
         }
         if (TimeStampURL != null)
         {
             hashCode = hashCode * 59 + TimeStampURL.GetHashCode();
         }
         if (TimeStampUserName != null)
         {
             hashCode = hashCode * 59 + TimeStampUserName.GetHashCode();
         }
         if (TimeStampPassword != null)
         {
             hashCode = hashCode * 59 + TimeStampPassword.GetHashCode();
         }
         hashCode = hashCode * 59 + Linearize.GetHashCode();
         hashCode = hashCode * 59 + DrawSignature.GetHashCode();
         hashCode = hashCode * 59 + PageNumber.GetHashCode();
         hashCode = hashCode * 59 + ShowValidationMark.GetHashCode();
         if (ImageData != null)
         {
             hashCode = hashCode * 59 + ImageData.GetHashCode();
         }
         if (SignatureLayout != null)
         {
             hashCode = hashCode * 59 + SignatureLayout.GetHashCode();
         }
         if (SignatureText != null)
         {
             hashCode = hashCode * 59 + SignatureText.GetHashCode();
         }
         return(hashCode);
     }
 }
示例#10
0
        /// <summary>
        /// Returns true if PdfDigiSignParameters instances are equal
        /// </summary>
        /// <param name="input">Instance of PdfDigiSignParameters to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(PdfDigiSignParameters input)
        {
            if (input == null)
            {
                return(false);
            }

            return
                ((
                     FileId == input.FileId ||
                     (FileId != null &&
                      FileId.Equals(input.FileId))
                     ) &&
                 (
                     CertificateData == input.CertificateData ||
                     (CertificateData != null &&
                      CertificateData.Equals(input.CertificateData))
                 ) &&
                 (
                     CertificatePassword == input.CertificatePassword ||
                     (CertificatePassword != null &&
                      CertificatePassword.Equals(input.CertificatePassword))
                 ) &&
                 (
                     SignatureMode == input.SignatureMode ||
                     SignatureMode.Equals(input.SignatureMode)
                 ) &&
                 (
                     SignatureCertificationLevel == input.SignatureCertificationLevel ||
                     SignatureCertificationLevel.Equals(input.SignatureCertificationLevel)
                 ) &&
                 (
                     SignatureHashAlgorithm == input.SignatureHashAlgorithm ||
                     SignatureHashAlgorithm.Equals(input.SignatureHashAlgorithm)
                 ) &&
                 (
                     SignerName == input.SignerName ||
                     (SignerName != null &&
                      SignerName.Equals(input.SignerName))
                 ) &&
                 (
                     Reason == input.Reason ||
                     (Reason != null &&
                      Reason.Equals(input.Reason))
                 ) &&
                 (
                     Location == input.Location ||
                     (Location != null &&
                      Location.Equals(input.Location))
                 ) &&
                 (
                     ContactInfo == input.ContactInfo ||
                     (ContactInfo != null &&
                      ContactInfo.Equals(input.ContactInfo))
                 ) &&
                 (
                     TimeStampURL == input.TimeStampURL ||
                     (TimeStampURL != null &&
                      TimeStampURL.Equals(input.TimeStampURL))
                 ) &&
                 (
                     TimeStampUserName == input.TimeStampUserName ||
                     (TimeStampUserName != null &&
                      TimeStampUserName.Equals(input.TimeStampUserName))
                 ) &&
                 (
                     TimeStampPassword == input.TimeStampPassword ||
                     (TimeStampPassword != null &&
                      TimeStampPassword.Equals(input.TimeStampPassword))
                 ) &&
                 (
                     Linearize == input.Linearize ||
                     Linearize.Equals(input.Linearize)
                 ) &&
                 (
                     DrawSignature == input.DrawSignature ||
                     DrawSignature.Equals(input.DrawSignature)
                 ) &&
                 (
                     PageNumber == input.PageNumber ||
                     PageNumber.Equals(input.PageNumber)
                 ) &&
                 (
                     ShowValidationMark == input.ShowValidationMark ||
                     ShowValidationMark.Equals(input.ShowValidationMark)
                 ) &&
                 (
                     ImageData == input.ImageData ||
                     (ImageData != null &&
                      ImageData.Equals(input.ImageData))
                 ) &&
                 (
                     SignatureLayout == input.SignatureLayout ||
                     (SignatureLayout != null &&
                      SignatureLayout.Equals(input.SignatureLayout))
                 ) &&
                 (
                     SignatureText == input.SignatureText ||
                     (SignatureText != null &&
                      SignatureText.Equals(input.SignatureText))
                 ));
        }