5,530,111 members and growing! (16,187 online)
Email Password   helpLost your password?
Platforms, Frameworks & Libraries » Mobile Development » General     Intermediate

Sign code

By crino

How sign the code by own certificate and install the certificate on device.
C++, Windows, Win Mobile, Mobile, Visual Studio, Dev

Posted: 19 Dec 2005
Updated: 15 Nov 2006
Views: 80,936
Bookmarked: 42 times
Announcements
Want a new Job?



Search    
Advanced Search
Sitemap
23 votes for this Article.
Popularity: 5.19 Rating: 3.81 out of 5
2 votes, 8.7%
1
1 vote, 4.3%
2
3 votes, 13.0%
3
2 votes, 8.7%
4
15 votes, 65.2%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

This article is for tests purpose only, the best way to sign code is Mobile2Market, Versign etc...
With WM5 Microsoft has implements a new security schema on PocketPC too.
The new schema requires that the applications must be signed with a valid certificate to run without problems on devices. 
For simple applications the schema is not a problem, you'll get some borings popup to run the applications or to install cabs the first time. We have more problems when we try to deploy services or drivers, our dlls or applications will not run because the schema is loaded after service.exe and device.exe processes!
In this article i'll explain how we can deploy our own certificate on device and sign our code.

Step 1 - Create the certificate

The first step is create our certificate.  To do this we'll use the utility makecert.exe:
makecert -r -sv MyCert.pvk -n "CN=MyCert" -b 01/01/2000 -e 01/01/2099 MyCert.cer 
For more information about makecert.exe parameters refer to MSDN library.
Now we have our certificate (MyCert.cer) and private key (MyCert.pvk) but we need of .pfx to pass it to signtool.exe, so go on step 2.

Step 2 - Create .pfx from the .cer

To create .pfx file from .cer file we've to run pvk2pfx.exe tool:
pvk2pfx.exe -pvk MyCert.pvk -spc MyCert.cer -pfx MyCert.pfx
The command will creates .pfx file (MyCert.pfx).

Step 3 - Create the provisioningdoc xml

Ok, now we are ready to build our cab which will installs our certificate on devices. To do this we've to create our wap-provisioningdoc xml.
<?xml version="1.0" encoding="utf-8" ?>
<wap-provisioningdoc>
<characteristic type="CertificateStore">
    <characteristic type="Privileged Execution Trust Authorities">
        <characteristic type="[cert_sha1]">
            <parm name="EncodedCertificate" value="[cert_base64]" />
        </characteristic>
    </characteristic>
</characteristic>
<characteristic type="CertificateStore">
    <characteristic type="SPC">
        <characteristic type="[cert_sha1]">
            <parm name="EncodedCertificate" value="[cert_base64]" />
            <parm name="Role" value="222" />
        </characteristic>
    </characteristic>
</characteristic>
</wap-provisioningdoc>
This is the standard schema for our provisioningdoc.
We've to fill [cert_sha1] and [cert_base64] with our values get from MyCert.cer. To obtain these values we've to use openssl.exe tool:
openssl sha1 MyCert.cer > MyCert_sha1.txt
openssl base64 -in MyCert.cer > MyCert_base64.txt
With these commands we get two files with sha1 and base64 values of our certificate. So create an empty file '_setup.xml' and past the content into:
<?xml version="1.0" encoding="utf-8" ?>
<wap-provisioningdoc>
<characteristic type="CertificateStore">
    <characteristic type="Privileged Execution Trust Authorities">
        <characteristic type="30bc827f441fa4437b645163e49ade7226b362c3">
            <parm name="EncodedCertificate" value="MIIB7zCCAVigAwIBAgIQSZfc9OLump1HzDNpsZ2edTANBgkqhkiG9w0BAQQFADAR
MQ8wDQYDVQQDEwZNeUNlcnQwIBcNOTkxMjMxMjMwMDAwWhgPMjA5ODEyMzEyMzAw
MDBaMBExDzANBgNVBAMTBk15Q2VydDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
gYEAx6QQIhONxvNHrK+p1qgy/AY3/Q/rf7XGvMYmxENAdQFjgP2CpH/1Bgsa8MwK
XxViZqW2DbixDas77M+cG3BnxtdK42xuhBlzVCq8wiOh7/q9SZp9wKj94c7k5jok
L1BgHT2dH2DHUgnxG6Y9mvowX/DJ8gvbNKR1p4FQpK74NvUCAwEAAaNGMEQwQgYD
VR0BBDswOYAQfyce0/6l1q4oeResHzIEZ6ETMBExDzANBgNVBAMTBk15Q2VydIIQ
SZfc9OLump1HzDNpsZ2edTANBgkqhkiG9w0BAQQFAAOBgQAEqy6rTbjmV/6zgYBY
+gQQqBHf4GMvyEUR9g5+p/esG7GDve/qbZ4bm1BOSdRfgzMsda2guciMD54QPHNp
k+wdE0tSuQN90Dla8109GmTdFyZkVezSDmuCkbX0BjQW2dJ6egvGG2mnA7Q6/5yt
4ftcV6hExesZviGUKXdBhBM2Dg==" />
        </characteristic>
    </characteristic>
</characteristic>
<characteristic type="CertificateStore">
    <characteristic type="SPC">
        <characteristic type="30bc827f441fa4437b645163e49ade7226b362c3">
            <parm name="EncodedCertificate" value="MIIB7zCCAVigAwIBAgIQSZfc9OLump1HzDNpsZ2edTANBgkqhkiG9w0BAQQFADAR
MQ8wDQYDVQQDEwZNeUNlcnQwIBcNOTkxMjMxMjMwMDAwWhgPMjA5ODEyMzEyMzAw
MDBaMBExDzANBgNVBAMTBk15Q2VydDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkC
gYEAx6QQIhONxvNHrK+p1qgy/AY3/Q/rf7XGvMYmxENAdQFjgP2CpH/1Bgsa8MwK
XxViZqW2DbixDas77M+cG3BnxtdK42xuhBlzVCq8wiOh7/q9SZp9wKj94c7k5jok
L1BgHT2dH2DHUgnxG6Y9mvowX/DJ8gvbNKR1p4FQpK74NvUCAwEAAaNGMEQwQgYD
VR0BBDswOYAQfyce0/6l1q4oeResHzIEZ6ETMBExDzANBgNVBAMTBk15Q2VydIIQ
SZfc9OLump1HzDNpsZ2edTANBgkqhkiG9w0BAQQFAAOBgQAEqy6rTbjmV/6zgYBY
+gQQqBHf4GMvyEUR9g5+p/esG7GDve/qbZ4bm1BOSdRfgzMsda2guciMD54QPHNp
k+wdE0tSuQN90Dla8109GmTdFyZkVezSDmuCkbX0BjQW2dJ6egvGG2mnA7Q6/5yt
4ftcV6hExesZviGUKXdBhBM2Dg==" />
            <parm name="Role" value="222" />
        </characteristic>
    </characteristic>
</characteristic>
</wap-provisioningdoc>
We're ready to build our cab to deploy on our devices.

Step 4 - Build the .cab

This is the most simple step, we've to run makecab.exe tool:
makecab.exe _setup.xml mycert_cert.cab
Our certificate is now ready to install on devices!

Step 5 - Sing our application code

After we installed the certificate on our devices we can sign our code with MyCert.pfx our code to run as trusted.
We've to use signtool.exe tool:
signtool.exe sign /f MyCert.pfx *.exe *.cab

or

signcode -v MyCert.pvk -spc MyCert.cer *.exe 
With these simple five steps we've our certificate applications!

History

19/12/2005 - Initial article.
30/12/2005 - Corrected the command line on Step 5
31/12/2005 - Regenerated the certificate and updated zip file
15/11/2006 - Added command line in Step 5 and updated zip file with signcode.exe tool.

Related links

Windows Mobile 5.0 Application Security
Secure Windows Mobile Development and Deployment
A Practical Guide to the Smartphone Application Security and Code Signing Model for Developers

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

crino



Location: Italy Italy

Other popular Mobile Development articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 25 of 48 (Total in Forum: 48) (Refresh)FirstPrevNext
Subject  Author Date 
QuestionPFX passwordmemberchmod222222:41 20 Jul '08  
AnswerRe: PFX passwordmemberchmod222222:57 20 Jul '08  
QuestionVb.Net [modified]memberhitesh sojitra22:25 7 May '08  
Generalwhen I generate the cab file, and check it's contents, the xml data is missing?memberMember 21595545:10 12 Dec '07  
GeneralSimple EXE signing...?memberVitalyTomilov2:52 10 Jan '07  
Questionsigning solution with several projectsmemberdonkaiser7:55 5 Dec '06  
AnswerRe: signing solution with several projectsmembercrino8:10 5 Dec '06  
Questionwhat does the value 222 means?memberdonkaiser5:00 28 Nov '06  
AnswerRe: what does the value 222 means?membercrino8:11 5 Dec '06  
QuestionDeploy application in Debug modememberDrca7:32 15 Nov '06  
AnswerRe: Deploy application in Debug modemembercrino9:25 15 Nov '06  
GeneralI can't install certificatememberRikardo3:01 15 Nov '06  
GeneralRe: I can't install certificatemembercrino6:09 15 Nov '06  
GeneralRe: I can't install certificatememberRikardo7:08 16 Nov '06  
GeneralRe: I can't install certificatemembercrino9:39 16 Nov '06  
NewsDownload for CAPICOMmemberivarklung22:54 1 Nov '06  
GeneralStill getting prompted?memberbobnob10:55 19 Jun '06  
GeneralPassword error [modified]memberthomasthethomas5:22 22 May '06  
GeneralRe: Password errormemberbuchser5:17 10 Aug '06  
GeneralRe: Password error [modified]membercrino6:13 15 Nov '06  
GeneralThanks!!memberNarin14:28 22 Apr '06  
GeneralSigned files dont workmemberaxbl0:28 1 Apr '06  
GeneralRe: Signed files dont workmembercrino0:39 1 Apr '06  
GeneralRe: Signed files dont workmemberaxbl2:02 1 Apr '06  
GeneralRe: Signed files dont workmembercrino2:11 1 Apr '06  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 15 Nov 2006
Editor:
Copyright 2005 by crino
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project