Skip to content

Commit dee3d10

Browse files
Merge pull request #134 from microsoft/user/elantigua/print-exception
BugFix: Include Exception in Verbose Out
2 parents c83ed24 + 2a6d96e commit dee3d10

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

CoseHandler/ValidationResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public readonly string ToString(bool verbose = false, bool showCertDetails = fal
129129
: string.Empty;
130130

131131
// Do the same for exceptions.
132-
List<Exception>? innerExceptions = allIncludes?.Where(e => e.GetType() == typeof(Exception)).Cast<Exception>().ToList();
132+
List<Exception>? innerExceptions = allIncludes?.Where(e => e.GetType().IsSubclassOf(typeof(Exception))).Cast<Exception>().ToList();
133133
string exceptionBlock =
134134
innerExceptions?.Count > 0
135135
? $"Exceptions:{newline}{string.Join(newline + tab, innerExceptions.Select(e => $"{e.GetType()}: {e.Message}"))}"

CoseSignTool.Tests/ValidateCommandTests.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,35 @@ public void ValidateSucceedsWithRootPassedIn()
149149
result.ToString(true).Should().Contain("Detached");
150150
}
151151

152+
/// <summary>
153+
/// Validates that signatures made from "untrusted" chains are accepted when root is passed in as trusted
154+
/// </summary>
155+
[TestMethod]
156+
public void ValidateFailsWithWrongCommonName()
157+
{
158+
string payloadFilePath = FileSystemUtils.GeneratePayloadFile();
159+
FileInfo payloadFile = new(payloadFilePath);
160+
string sigFilePath = $"{payloadFilePath}.cose";
161+
FileInfo sigFile = new(sigFilePath);
162+
163+
// sign detached
164+
CoseHandler.Sign(File.ReadAllBytes(payloadFilePath), new X509Certificate2CoseSigningKeyProvider(null, Leaf1Priv, [Int1Priv]), false, sigFile);
165+
166+
string commonName = $"CN={Guid.NewGuid()}";
167+
168+
var validator = new ValidateCommand();
169+
var result = validator.RunCoseHandlerCommand(
170+
sigFile.OpenRead(),
171+
payloadFile,
172+
[Root1Priv],
173+
X509RevocationMode.NoCheck,
174+
commonName);
175+
176+
result.Success.Should().BeFalse();
177+
result.ContentValidationType.Should().Be(ContentValidationType.ContentValidationNotPerformed);
178+
result.ToString(true).Should().Contain(commonName);
179+
}
180+
152181
/// <summary>
153182
/// Validates that modified payloads are rejected
154183
/// </summary>

0 commit comments

Comments
 (0)