Home All Groups Group Topic Archive Search About

sn.exe exit code documentation ?

Author
3 Aug 2005 7:47 AM
Thibaut
Hi,

When one calls sn.exe, what are the expected error codes (errorlevel) in
return ?

I'm using delay signing. I think about three cases when achieving the final
signing:
- assembly was signed successfully (seems to be errorlevel 0)
- assembly was not signed because it's already signed with the provided key
- assembly could not be signed (either because it's already signed with
another key, or file not found etc)

I could not find anything related to those exit codes in the documentation.
Is there any official reference for that ?

kind regards

Thibaut Barrère

[note: this is a cross post from
http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=66938 / there is much
more traffic here]

Author
3 Aug 2005 12:34 PM
Nicole Calinoiu
"Thibaut" <Thib***@discussions.microsoft.com> wrote in message
news:B67FFB0F-BBBB-4CB3-8554-0B924F8FBE04@microsoft.com...
> Hi,
>
> When one calls sn.exe, what are the expected error codes (errorlevel) in
> return ?
>
> I'm using delay signing. I think about three cases when achieving the
> final
> signing:
> - assembly was signed successfully (seems to be errorlevel 0)
> - assembly was not signed because it's already signed with the provided
> key

Actually, it'll be resigned anyway, so it should simply appear to be a
successful signing (exit code 0).


> - assembly could not be signed (either because it's already signed with
> another key,

Again, it'll be resigned anyway (even though, in this case, the assembly
will not be loadable since the signature and the key won't match), so the
exit code is 0.


> or file not found etc)

I know of no documentation regarding the exit codes in sn.exe error
scenarios.  However, a quick test shows that the exit code is 1 in at least
the three following cases:

1.  Target assembly does not exist.
2.  Signing key container does not exist.
3.  Signing key file does not exist.

I'm guessing that other error scenarios may also yield the same result code.
If you want to be able to distinguish between them, it looks like you'll
probably need to capture and process the output messages generated by
sn.exe.


Show quoteHide quote
>
> I could not find anything related to those exit codes in the
> documentation.
> Is there any official reference for that ?
>
> kind regards
>
> Thibaut Barrère
>
> [note: this is a cross post from
> http://forums.microsoft.com/msdn/ShowPost.aspx?PostID=66938 / there is
> much
> more traffic here]
Author
3 Aug 2005 3:36 PM
William Stacey [MVP]
> Again, it'll be resigned anyway (even though, in this case, the assembly
> will not be loadable since the signature and the key won't match), so the
> exit code is 0.

I may be missing something here, but sn will not resign an assembly that has
already been signed by another key - you will get the "Key pair does not
match public key from assembly --" error.  You will have to change the
public key inside the assembly first and then resign with sn.

--
William Stacey [MVP]
Author
3 Aug 2005 4:02 PM
Nicole Calinoiu
That would be v. 2.0 behaviour.  In v. 1.x, sn.exe doesn't verify the
details of the current key before re-signing with the specified key.



Show quoteHide quote
"William Stacey [MVP]" <stac***@mvps.org> wrote in message
news:ul9MpEEmFHA.3312@tk2msftngp13.phx.gbl...
>> Again, it'll be resigned anyway (even though, in this case, the assembly
>> will not be loadable since the signature and the key won't match), so the
>> exit code is 0.
>
> I may be missing something here, but sn will not resign an assembly that
> has already been signed by another key - you will get the "Key pair does
> not match public key from assembly --" error.  You will have to change the
> public key inside the assembly first and then resign with sn.
>
> --
> William Stacey [MVP]
>
>
>
Author
3 Aug 2005 4:22 PM
William Stacey [MVP]
hmm.  I thought I remember the same behavior in 1.1.  I don't have a 1.1
build to test with, but assume you tried it already.  Do you (or others)
know if you can load an already signed assem and resign it in code (in 2.0)?
If so, any examples?  TIA

--
William Stacey [MVP]

Show quoteHide quote
"Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
news:OT2M9SEmFHA.2444@tk2msftngp13.phx.gbl...
> That would be v. 2.0 behaviour.  In v. 1.x, sn.exe doesn't verify the
> details of the current key before re-signing with the specified key.
>
>
>
> "William Stacey [MVP]" <stac***@mvps.org> wrote in message
> news:ul9MpEEmFHA.3312@tk2msftngp13.phx.gbl...
>>> Again, it'll be resigned anyway (even though, in this case, the assembly
>>> will not be loadable since the signature and the key won't match), so
>>> the exit code is 0.
>>
>> I may be missing something here, but sn will not resign an assembly that
>> has already been signed by another key - you will get the "Key pair does
>> not match public key from assembly --" error.  You will have to change
>> the public key inside the assembly first and then resign with sn.
>>
>> --
>> William Stacey [MVP]
>>
>>
>>
>
>
Author
5 Aug 2005 11:06 AM
Nicole Calinoiu
"William Stacey [MVP]" <stac***@mvps.org> wrote in message
news:O$AENeEmFHA.3552@TK2MSFTNGP10.phx.gbl...
> hmm.  I thought I remember the same behavior in 1.1.  I don't have a 1.1
> build to test with, but assume you tried it already.

Yup.


> Do you (or others) know if you can load an already signed assem and resign
> it in code (in 2.0)?

I haven't tried it, but I suspect that it's most likely possible.  One
obvious approach to try would  be "reversion" to a delay-signed state in
order to apply one's preferred key.  Is there any particular reason you're
interested in this scenario (other than, say, simple curiosity about the
ease of hacking the signature <g>)?


Show quoteHide quote
> If so, any examples?  TIA
>
> --
> William Stacey [MVP]
>
> "Nicole Calinoiu" <calinoiu REMOVETHIS AT gmail DOT com> wrote in message
> news:OT2M9SEmFHA.2444@tk2msftngp13.phx.gbl...
>> That would be v. 2.0 behaviour.  In v. 1.x, sn.exe doesn't verify the
>> details of the current key before re-signing with the specified key.
>>
>>
>>
>> "William Stacey [MVP]" <stac***@mvps.org> wrote in message
>> news:ul9MpEEmFHA.3312@tk2msftngp13.phx.gbl...
>>>> Again, it'll be resigned anyway (even though, in this case, the
>>>> assembly will not be loadable since the signature and the key won't
>>>> match), so the exit code is 0.
>>>
>>> I may be missing something here, but sn will not resign an assembly that
>>> has already been signed by another key - you will get the "Key pair does
>>> not match public key from assembly --" error.  You will have to change
>>> the public key inside the assembly first and then resign with sn.
>>>
>>> --
>>> William Stacey [MVP]
>>>
>>>
>>>
>>
>>
>
>