-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_crq.cpp
More file actions
137 lines (129 loc) · 3.83 KB
/
gen_crq.cpp
File metadata and controls
137 lines (129 loc) · 3.83 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/***************************************************************************
gen_crq.cpp - description
-------------------
begin : Sat Dec 14 2002
copyright : (C) 2002 by ARRL
author : Jon Bloom
email : jbloom@arrl.org
revision : $Id$
Generates a set of certificate-request files.
***************************************************************************/
#ifdef HAVE_CONFIG_H
#include "sysconfig.h"
#endif
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <unistd.h>
#include <exception>
#ifdef HAVE_GETOPT_H
#include <getopt.h>
#endif
#include <string.h>
#include <stdlib.h>
#include "tqsllib.h"
#include "tqslexc.h"
using std::cerr;
using std::endl;
int
usage() {
std::cerr << "Usage: -e email -d dxcc [-c sign_call] [-x sign_dxcc] call1 [call2 ...]" << endl;
exit(EXIT_FAILURE);
}
int
main(int argc, char *argv[]) {
string sign_call, email_addr;
int dxcc = 0, sign_dxcc = 0;
tQSL_Cert sign_cert = 0;
try {
if (tqsl_init())
throw tqslexc();
int c;
while ((c = getopt(argc, argv, "c:x:e:d:")) != -1) {
switch (c) {
case 'c':
sign_call = optarg;
break;
case 'x':
sign_dxcc = strtol(optarg, NULL, 10);
break;
case 'd':
dxcc = strtol(optarg, NULL, 10);
break;
case 'e':
email_addr = optarg;
break;
default:
usage();
}
}
if (optind >= argc || email_addr == "" || dxcc == 0)
usage();
if (sign_call != "") {
// if (sign_dxcc == 0)
// usage();
tQSL_Cert *list;
int ncerts;
if (tqsl_selectCertificates(&list, &ncerts, sign_call.c_str(), sign_dxcc, 0, 0, 1))
throw tqslexc();
if (ncerts < 1) {
string erm = "No signing certificate found for " + sign_call;
if (sign_dxcc) {
const char *entity;
tqsl_getDXCCEntityName(sign_dxcc, &entity);
erm += " with DXCC Entity=";
erm += entity;
}
throw myexc(erm);
}
sign_cert = *list;
} else if (sign_dxcc != 0) {
usage();
}
if (sign_cert) {
char buf[512];
long serial;
int cdxcc;
if (tqsl_getCertificateIssuer(sign_cert, buf, sizeof buf))
throw tqslexc();
if (tqsl_getCertificateSerial(sign_cert, &serial))
throw tqslexc();
if (tqsl_getCertificateDXCCEntity(sign_cert, &cdxcc))
throw tqslexc();
std::cout << "Signing certificate issuer: " << buf << endl;
std::cout << "Signing certificate serial: " << serial << endl;
std::cout << " Signing certificate DXCC: " << cdxcc << endl;
if (tqsl_beginSigning(sign_cert, const_cast<char *>(""), 0, 0))
throw tqslexc();
}
TQSL_CERT_REQ crq;
memset(&crq, 0, sizeof crq);
strncpy(crq.name, "Ish Kabibble", sizeof crq.name);
strncpy(crq.address1, "1 No Place", sizeof crq.address1);
strncpy(crq.city, "City", sizeof crq.city);
strncpy(crq.state, "ST", sizeof crq.state);
strncpy(crq.country, "USA", sizeof crq.country);
strncpy(crq.emailAddress, email_addr.c_str(), sizeof crq.emailAddress);
crq.dxccEntity = dxcc;
tqsl_initDate(&crq.qsoNotBefore, "1945-11-15");
crq.signer = sign_cert;
for (; optind < argc; optind++) {
string call = argv[optind];
strncpy(crq.callSign, call.c_str(), sizeof crq.callSign);
for (char *cp = argv[optind]; *cp; cp++) {
if (*cp == '/')
*cp = '_';
}
string filename = string(argv[optind]) + ".tq5";
std::cout << "Creating CRQ for " << crq.callSign << " DXCC=" << crq.dxccEntity << endl;
if (tqsl_createCertRequest(filename.c_str(), &crq, 0, 0))
throw tqslexc();
}
return EXIT_SUCCESS;
} catch(exception& x) {
std::cerr << "Aborting: " << x.what() << endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}