public SignatureVerificationSummary(
     SignatureType signatureType,
     SignatureVerificationStatus status,
     SignatureVerificationStatusFlags flags)
     : this(signatureType, status, flags, timestamp : null, expirationTime : null)
 {
 }
Ejemplo n.º 2
0
 public SignatureVerificationSummary(
     SignatureType signatureType,
     SignatureVerificationStatus status,
     SignatureVerificationStatusFlags flags,
     IEnumerable <SignatureLog> issues)
     : this(signatureType, status, flags, timestamp : null, expirationTime : null, issues : issues)
 {
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Get a valid timestamp from the unsigned attributes if present
        /// </summary>
        /// <param name="settings">Specify what is allowed in the validation for timestamp</param>
        /// <param name="fingerprintAlgorithm">fingerprint algorithm for displaying timestamp's certificate information</param>
        /// <param name="issues">List of log messages.</param>
        /// <param name="verificationFlags">Flags that specify the status of the verification</param>
        /// <param name="validTimestamp">TTimestamp found in the signature that passes validation with the given <see cref="settings"/></param>
        /// <remarks>If <see cref="SignedPackageVerifierSettings.AllowNoTimestamp" /> is set to true this method return true with a <see cref="validTimestamp" /> set to null.</remarks>
        /// <returns>true if a valid timestamp was found</returns>
        internal bool TryGetValidTimestamp(
            SignedPackageVerifierSettings settings,
            HashAlgorithmName fingerprintAlgorithm,
            List <SignatureLog> issues,
            out SignatureVerificationStatusFlags verificationFlags,
            out Timestamp validTimestamp)
        {
            if (issues == null)
            {
                throw new ArgumentNullException(nameof(issues));
            }

            if (settings == null)
            {
                throw new ArgumentNullException(nameof(settings));
            }

            verificationFlags = SignatureVerificationStatusFlags.NoErrors;
            validTimestamp    = null;

            var timestamps = Timestamps;

            if (timestamps.Count == 0)
            {
                issues.Add(SignatureLog.Issue(!settings.AllowNoTimestamp, NuGetLogCode.NU3027, Strings.ErrorNoTimestamp));
                if (!settings.AllowNoTimestamp)
                {
                    verificationFlags |= SignatureVerificationStatusFlags.NoValidTimestamp;
                    return(false);
                }
            }

            if (timestamps.Count > 1 && !settings.AllowMultipleTimestamps)
            {
                issues.Add(SignatureLog.Error(NuGetLogCode.NU3000, Strings.ErrorMultipleTimestamps));
                verificationFlags |= SignatureVerificationStatusFlags.MultipleTimestamps;
                return(false);
            }

            var timestamp = timestamps.FirstOrDefault();

            if (timestamp != null)
            {
                verificationFlags |= timestamp.Verify(this, settings, fingerprintAlgorithm, issues);

                if (verificationFlags != SignatureVerificationStatusFlags.NoErrors &&
                    verificationFlags != SignatureVerificationStatusFlags.UnknownRevocation)
                {
                    return(false);
                }

                validTimestamp = timestamp;
            }

            return(true);
        }
 public SignatureVerificationSummary(
     SignatureType signatureType,
     SignatureVerificationStatus status,
     SignatureVerificationStatusFlags flags,
     Timestamp timestamp,
     DateTimeOffset?expirationTime)
 {
     SignatureType  = signatureType;
     Status         = status;
     Flags          = flags;
     Timestamp      = timestamp;
     ExpirationTime = expirationTime;
 }
Ejemplo n.º 5
0
 public SignatureVerificationSummary(
     SignatureType signatureType,
     SignatureVerificationStatus status,
     SignatureVerificationStatusFlags flags,
     Timestamp timestamp,
     DateTimeOffset?expirationTime,
     IEnumerable <SignatureLog> issues)
 {
     SignatureType  = signatureType;
     Status         = status;
     Flags          = flags;
     Timestamp      = timestamp;
     ExpirationTime = expirationTime;
     Issues         = issues;
 }
Ejemplo n.º 6
0
        public static SignatureVerificationStatus GetSignatureVerificationStatus(SignatureVerificationStatusFlags flags)
        {
            if (flags == SignatureVerificationStatusFlags.NoErrors)
            {
                return(SignatureVerificationStatus.Valid);
            }

            if ((flags & SignatureVerificationStatusFlags.Suspect) != 0)
            {
                return(SignatureVerificationStatus.Suspect);
            }

            // If the only flags are these known ones, return disallowed.
            if ((flags & ~(SignatureVerificationStatusFlags.Illegal |
                           SignatureVerificationStatusFlags.Untrusted |
                           SignatureVerificationStatusFlags.NoValidTimestamp |
                           SignatureVerificationStatusFlags.MultipleTimestamps)) == 0)
            {
                return(SignatureVerificationStatus.Disallowed);
            }

            return(SignatureVerificationStatus.Unknown);
        }
Ejemplo n.º 7
0
        public static SignatureVerificationStatus GetSignatureVerificationStatus(SignatureVerificationStatusFlags flags)
        {
            if ((flags & SignatureVerificationStatusFlags.Suspect) != 0)
            {
                return(SignatureVerificationStatus.Suspect);
            }

            if ((flags & SignatureVerificationStatusFlags.Illegal) != 0)
            {
                return(SignatureVerificationStatus.Illegal);
            }

            if ((flags & SignatureVerificationStatusFlags.Untrusted) != 0)
            {
                return(SignatureVerificationStatus.Untrusted);
            }

            if (flags == SignatureVerificationStatusFlags.NoErrors)
            {
                return(SignatureVerificationStatus.Valid);
            }

            return(SignatureVerificationStatus.Unknown);
        }
Ejemplo n.º 8
0
 public void GetSignatureVerificationStatus_WithStatusFlag_ReturnsStatus(
     SignatureVerificationStatusFlags flags,
     SignatureVerificationStatus expectedStatus)
 {
     Assert.Equal(expectedStatus, VerificationUtility.GetSignatureVerificationStatus(flags));
 }