File: reqtest.cc

package info (click to toggle)
wvstreams 4.0.2-4
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 6,420 kB
  • ctags: 6,518
  • sloc: cpp: 52,544; sh: 5,770; ansic: 810; makefile: 461; tcl: 114; perl: 18
file content (41 lines) | stat: -rw-r--r-- 1,109 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#include "wvx509.h"
#include "wvlog.h"

// Quick program to test the certificate request generation routines
// from WvX509Mgr. Output should be put through:
// openssl req -text
// (The part between ----BEGIN CERTIFICATE REQUEST---- and 
// ----END CERTIFICATE REQUEST---- )

int main(int argc, char **argv)
{
    free(malloc(1)); // For Electric Fence...
    
    WvString request;
    
    WvLog log("reqtest", WvLog::Info);
    log("Starting...\n");
    
    // Setup a new DN entry, like a server would set.
    WvString dn(argc > 1 ? argv[1] : "cn=test.foo.com,dc=foo,dc=com");
    
    // Create a new certificate
    WvX509Mgr cert(dn, 1024);
    
    if (!cert.isok())
    {
	log("Failed to generate certificate: %s\n", cert.errstr());
	return 1;
    }
    
    log("Private RSA key follows (KEEP THIS!):\n");
    wvcon->write(cert.encode(WvX509Mgr::RsaPEM));
    
    log("Temporary self-signed certificate follows (replace later):\n");
    wvcon->write(cert.encode(WvX509Mgr::CertPEM));
    
    log("Certificate request follows:\n");
    wvcon->write(cert.certreq());
    
    log("Done...\n");
}