├── .travis.yml
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── spki
└── test
├── config
├── test.bats
└── test_helpers.bash
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: bash
2 | dist: bionic
3 | before_install:
4 | - sudo apt-get update
5 | - sudo apt-get -y install aptitude
6 | - sudo aptitude -y install nodejs npm openjdk-11-jdk shellcheck
7 | - sudo npm install -g bats http-server
8 | install: skip
9 | script:
10 | - bats ./test/test.bats
11 | - shellcheck -e SC2015 -e SC2016 ./spki
12 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 | Pull requests are welcome to fix bugs or add features. Please respect the conventions of the script (e.g. variable naming style, indent using tabs), and submit PR's to the develop branch.
3 |
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://travis-ci.com/kaysond/spki)
2 | # Simple PKI
3 | `spki` is a bash script wrapper for [OpenSSL](https://github.com/openssl/openssl) that generates and manages a simple PKI suitable for small deployments. It supports both CRL's and OCSP.
4 |
5 | The wrapper is based on Jamie Nguyen's guide: [OpenSSL Certificate Authority](https://jamielinux.com/docs/openssl-certificate-authority/ )
6 | ## Installation
7 | Copy the latest release of `spki` to a location in your path. [Releases](https://github.com/kaysond/spki/releases) use [semantic versioning](https://semver.org/) to identify backwards-incompatible changes.
8 |
9 | ## Configuration
10 | The top of the script contains several configuration variables; the defaults correspond to the guide. External configuration methods that do not require script modification are also supported (see below).
11 |
12 | `ROOT_DIR` - The base directory where all PKI files are stored
13 |
14 | `ROOT_PREFIX` - Prefix for all Root CA files
15 |
16 | `INTRMDT_PREFIX` - Prefix for all Intermediate CA files
17 |
18 | ### Certificate Revocation List (CRL)
19 | CRL's are automatically generated during initialization if either or both of the DP variables are set. The Intermedate CA Certificate will use the Root CRL DP; all other generated certificates use the Intermediate CRL DP. CRL's are automatically updated on revocation. CRL's served over http should **not** use https. Since the CRL files are frequently regenerated, it is recommended to serve the file directly from the spki root folder, for example by using a soft link. Furthermore, the CRL's are checked during initialization and certificate creation, so it is recommended to prepare the server in advance.
20 |
21 | `ROOT_CRL_DP` - CRL Distribution Point for the Root CA (e.g. 'URI:http://domain.com/my.crl,URI:http://backup.domain.com/my.crl')
22 |
23 | `INTRMDT_CRL_DP` - CRL Distribution Point for the Intermediate CA (e.g. 'URI:http://domain.com/my.crl,URI:http://backup.domain.com/my.crl')
24 |
25 | ### Online Certificate Status Protocol (OCSP)
26 | OCSP signing keys are automatically generated during initialization if either or both of the OCSP variables are set.
27 |
28 | `ROOT_OCSP` - Root CA OCSP Server (e.g. 'URI:http://ocsp.domain.com')
29 |
30 | `INTRMDT_OCSP`- Intermediate CA OCSP (e.g. 'URI:http://ocsp.domain.com')
31 |
32 | ### OpenSSL DN Defaults
33 | `spki init` prompts for the default values for certificate Distinguished Name parts and stores them in the OpenSSL configuration file. These can also be specified programmatically by using the following variables:
34 |
35 | * `countryName`
36 | * `stateOrProvinceName`
37 | * `localityName`
38 | * `organizationalUnitName`
39 | * `organizationName`
40 | * `emailAddress`
41 |
42 | (or set them to '.' to prevent prompting that field)
43 |
44 | ### External Configuration
45 | Configuration can be specified externally, without modifying the script, via environment variables. The precedence order of the configuration methods is:
46 | 1. Configuration File
47 | 2. Environment Variables
48 | 3. In-script Variables
49 |
50 | #### Configuration File
51 | The configuration file can be specified in the environment variable `SPKI_CONFIG_FILE`. This file is loaded directly by bash and should contain a list of local variable definitions such as
52 | ```
53 | ROOT_DIR=/root/ca
54 | ROOT_PREFIX=root
55 | countryName=US
56 | ```
57 |
58 | Note: If this file is loaded, all other environment variables are ignored.
59 |
60 | #### Environment Variables
61 | Variables defined in the script itself can be overriden by environment variables. The environment variable name should be those in the script but prefixed with `SPKI_` (e.g. `SPKI_ROOT_DIR` and `SPKI_ROOT_CRL_DP`).
62 |
63 | ## Usage
64 | * `spki init` - Initialize the PKI. This process first sets up the default Subject fields in the OpenSSL configuration files, then generates the Root CA, Intermediate CA, and a combined CA chain file. CRL's and OCSP certificates are also generated
65 | * `spki create (server | user | client_server) ` - Create and sign a key pair with the Intermediate CA. `server`, `user` or `client_server` specifies particular extensions to use. These can be modified by changing the configuration files after initialization. The `file-prefix` is prepended to various file extensions (`.key.pem`, `.cert.pem`, `.csr.pem`)
66 | * `server`
67 | * `nsCertType = server`
68 | * `authorityKeyIdentifier = keyid,issuer:always`
69 | * `keyUsage = critical, digitalSignature, keyEncipherment`
70 | * `extendedKeyUsage = serverAuth`
71 |
72 | * `user`
73 | * `nsCertType = client, email`
74 | * `authorityKeyIdentifier = keyid,issuer`
75 | * `keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment`
76 | * `extendedKeyUsage = clientAuth, emailProtection`
77 |
78 | * `client_server`
79 | * `nsCertType = client, server`
80 | * `authorityKeyIdentifier = keyid,issuer`
81 | * `keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment`
82 | * `extendedKeyUsage = clientAuth, serverAuth`
83 |
84 | * `spki create-intermediate` - Recreate the Intermediate CA key and certificate. This command also regenerates the Intermediate CRL if necessary
85 | * `spki sign (server | user | client_server) ` - Sign a specified `CSR` file with the `server`, `user` or `client_server` extensions (see above). `certificate` specifies the output file
86 | * `spki list` - List all of the certificates signed by the Intermediate CA, including expiration times and revocation times
87 | * `spki verify-intermediate` - Dump the intermediate CA certificate information and verify the chain of trust using the Root CA certificate
88 | * `spki verify (certificate | file-prefix)` - Dump the certificate information and verify the chain of trust using the Root CA->Intermediate CA chain. Can be specified as a file or as the prefix used in `spki create`
89 | * `spki export-pkcs12 ` - Export the key, certificate, and CA chain file to pkcs12 format
90 | * `spki export-truststore ` - Export CA chain file to pkcs12 format compatible with java expectations. Requires keytool (bundled with java)
91 | * `spki revoke (certificate | file-prefix) [reason]` - Revoke the specified certificate. `reason` can be one of: `unspecified`, `keyCompromise`, `CACompromise`, `affiliationChanged`, `superseded`, `cessationOfOperation`, `certificateHold`. This command automatically regenerates the Intermediate CRL
92 | * `spki revoke-intermediate [reason]` - Revoke the Intermediate CA certificate. `reason` can be one of the options above. This command automatically regenerates the Root CRL
93 | * `spki list-crl` - Dump information about the CRL's and the revoked certificates
94 | * `spki generate-crl [-rootca]` - Generate the Intermediate CRL file. This should be run regularly. Pass `-rootca` to generate the Root CRL file
95 | * `spki generate-ocsp [-rootca]` - Generate the Intermediate OCSP signing pair. Pass `-rootca` to generate the Root OCSP signing pair
96 | * `spki ocsp-responder [-rootca]` - Start an OCSP responder on the specified port using `openssl ocsp`. The command by default uses the Intermediate CA database, but can be changed to the Root CA database by passing `-rootca`. This can be turned into a service by using `systemd`, for example, but the OpenSSL OCSP responder may not be suitable for high traffic.
97 | * `spki ocsp-query (certificate | file-prefix) [-rootca]` - Send an OCSP query for the specified certificate to the specified url (e.g. http://127.0.0.1:12345). The command uses the full chain file by default, suitable for verifying certificates signed by the Intermediate CA. Specify `-rootca` to use just the Root CA, suitable for verifying the Intermediate CA certificate.
98 | * `spki update-config` - Regenerate the openssl configuration files. This allows the configuration variables, such as CRL or OCSP to be updated. It re-prompts for the certificate defaults.
99 |
100 | ## Automating `spki init`
101 |
102 | You can automate the PKI initialization by doing the following.
103 |
104 | Prepare a configuration file named `config`, making sure to specify default DN parts (`countryName`, `stateOrProvinceName`, `localityName`, etc.) i.e.:
105 | ```
106 | ROOT_DIR=/tmp/spki/
107 | countryName=PL
108 | stateOrProvinceName=Warsaw
109 | localityName=Warsaw
110 | organizationalUnitName=Developers
111 | organizationName=Company Ltd
112 | emailAddress=mail@company.com
113 | ```
114 |
115 | Then use following script to create the PKI and a certificate in one go:
116 | ```bash
117 | SPKI_CONFIG_FILE=$(pwd)/config
118 | export SPKI_CONFIG_FILE
119 |
120 | source $SPKI_CONFIG_FILE
121 |
122 | ROOT_PRIVATE_KEY_PASSWORD=""
123 | ROOT_COMMON_NAME="Root CA"
124 | ROOT_COUNTRY_NAME="$countryName"
125 | ROOT_PROVINCE_NAME="$stateOrProvinceName"
126 | ROOT_LOCALITY_NAME="$localityName"
127 | ROOT_ORGANIZATION_NAME="$organizationName"
128 | ROOT_ORGANIZATIONAL_UNIT_NAME="$organizationalUnitName"
129 | ROOT_MAIL="$emailAddress"
130 |
131 | INTERMEDIATE_COMMON_NAME="Intermediate CA"
132 | INTERMEDIATE_COUNTRY_NAME="$countryName"
133 | INTERMEDIATE_PROVINCE_NAME="$stateOrProvinceName"
134 | INTERMEDIATE_LOCALITY_NAME="$localityName"
135 | INTERMEDIATE_ORGANIZATION_NAME="$organizationName"
136 | INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME="$organizationalUnitName"
137 | INTERMEDIATE_MAIL="$emailAddress"
138 |
139 | INTERMEDIATE_PRIVATE_KEY_PASSWORD=""
140 |
141 | ANYKEY="k"
142 | YES="y"
143 |
144 | ./spki init <&/dev/null || {
90 | echoc "Could not remove $ROOT_DIR" red >&2
91 | return 1
92 | }
93 | fi
94 | mkdir -p "$ROOT_DIR" >&/dev/null || {
95 | echoc "Could not create '$ROOT_DIR'" red >&2
96 | return 1
97 | }
98 |
99 | echoc 'Preparing root directory' green
100 | prep-directory "$ROOT_DIR" || return 1
101 | get-default-fields
102 |
103 | echoc 'Writing root configuration file' green
104 | write-root-conf || return 1
105 |
106 | echoc 'Creating root CA private key' green
107 | ROOT_PASS=$(get-password 'root CA private key')
108 | exec 3<<<"$ROOT_PASS"
109 | openssl genrsa -aes256 -out "$ROOT_KEY" -passout "fd:3" 4096 |& indent &&
110 | chmod 400 "$ROOT_KEY" || {
111 | echoc 'Could not create root CA key' red >&2
112 | return 1
113 | }
114 |
115 | echoc 'Creating root CA certificate' green
116 |
117 | exec 3<<<"$ROOT_PASS"
118 | openssl req -verbose -config "$ROOT_CONF" \
119 | -key "$ROOT_KEY" \
120 | -new -x509 -days 7300 -sha256 -extensions v3_ca \
121 | -out "$ROOT_CERT" -passin "fd:3" &&
122 | chmod 444 "$ROOT_CERT" || {
123 | echoc 'Could not create root CA certificate' red >&2
124 | return 1
125 | }
126 |
127 | echoc 'Verifying root CA cert' green
128 | openssl x509 -noout -text -in "$ROOT_CERT" | remove_openssl_hex | indent || {
129 | echoc 'Could not verify root CA certificate' red >&2
130 | return 1
131 | }
132 |
133 | echoc 'Press any key to continue...' yellow | indent
134 | read -n1 -r -s
135 |
136 | generate-crl -rootca || exit 1
137 | # The Intermediate CRL is created in the create-intermediate call
138 |
139 | # https://jamielinux.com/docs/openssl-certificate-authority/create-the-intermediate-pair.html
140 | echoc 'Creating intermediate CA directory' green
141 | if [ ! -d "$INTRMDT_DIR" ]; then
142 | mkdir -p "$INTRMDT_DIR" >&/dev/null || {
143 | echoc "Could not create '$INTRMDT_DIR'" red >&2
144 | return 1
145 | }
146 | fi
147 | echoc 'Preparing intermediate CA directory' green
148 | prep-directory "$INTRMDT_DIR" || exit 1
149 | echoc 'Writing intermediate CA configuration file' green
150 | write-intermediate-conf || return 1
151 |
152 | create-intermediate || return 1
153 |
154 | echo
155 | echoc 'Creating certificate chain' green
156 | cat "$INTRMDT_CERT" "$ROOT_CERT" >"$CA_CHAIN" &&
157 | chmod 444 "$CA_CHAIN" || {
158 | echoc 'Could not create certificate chain' red >&2
159 | return 1
160 | }
161 |
162 | generate-ocsp -rootca || exit 1
163 | generate-ocsp || exit 1
164 |
165 | echo
166 | echoc 'The following configuration files were created:' green
167 | echoc "Root CA: $ROOT_CONF" | indent
168 | echoc "Intermediate CA: $INTRMDT_CONF" | indent
169 | echo
170 | echoc 'The following certificates were created:' green
171 | echoc "Root CA: $ROOT_CERT" | indent
172 | echoc "Intermediate CA: $INTRMDT_CERT" | indent
173 | echo
174 | echoc 'The following private keys were created:' green
175 | echoc "Root CA: $ROOT_KEY" | indent
176 | echoc "Intermediate CA: $INTRMDT_KEY" | indent
177 | echo
178 |
179 | if [[ -n $ROOT_CRL_DP || -n $INTRMDT_CRL_DP ]]; then
180 | echoc 'The following CRLs were created:' green
181 | if [[ -n $ROOT_CRL_DP ]]; then
182 | echoc "Root CA: $ROOT_CRL" | indent
183 | fi
184 | if [[ -n $INTRMDT_CRL_DP ]]; then
185 | echoc "Intermediate CA: $INTRMDT_CRL" | indent
186 | fi
187 | echo
188 | echoc 'CRLs must be regenerated at regular intervals (Intermediate: 30 days, Root: 4 years). Use `spki generate-crl`' yellow | indent
189 | echo
190 | fi
191 | if [[ -n $ROOT_OCSP || -n $INTRMDT_OCSP ]]; then
192 | echoc 'The following OCSP certificates were created:' green
193 | if [[ -n $ROOT_OCSP ]]; then
194 | echoc "Root CA: $ROOT_OCSP_CERT" | indent
195 | fi
196 | if [[ -n $INTRMDT_OCSP ]]; then
197 | echoc "Intermediate CA: $INTRMDT_OCSP_CERT" | indent
198 | fi
199 | echo
200 | fi
201 |
202 | echoc '**********************************!!WARNING!!***********************************' red
203 | echoc '*Security of the Root CA Private Key is critical!' red
204 | echoc '*It is highly recommended to store this key offline.' red
205 | echoc '*Consider generating it on an air-gapped system and using `shred` to remove it.' red
206 | echoc '********************************************************************************' red
207 | echo
208 | echoc 'DONE!' greenbold
209 | }
210 |
211 | create() {
212 | # https://jamielinux.com/docs/openssl-certificate-authority/sign-server-and-client-certificates.html
213 | PREFIX="$2"
214 | KEY="$INTRMDT_DIR/private/$PREFIX.key.pem"
215 | CSR="$INTRMDT_DIR/csr/$PREFIX.csr.pem"
216 | CERT="$INTRMDT_DIR/certs/$PREFIX.cert.pem"
217 | echoc 'Creating private key' green
218 | PASS=$(get-password 'private key')
219 | exec 3<<<"$PASS"
220 | if [[ -z "$CERT_ENCRYPTION" ]]; then
221 | openssl genrsa -out "$KEY" -passout fd:3 2048 |& indent
222 | else
223 | openssl genrsa -"$CERT_ENCRYPTION" -out "$KEY" -passout fd:3 2048 |& indent
224 | fi &&
225 | chmod 400 "$KEY" &&
226 | echoc 'Creating CSR' green
227 | exec 3<<<"$PASS"
228 | if [[ "$3" == "-SAN" ]]; then
229 | openssl req -verbose -reqexts SAN -config <(cat "$INTRMDT_CONF" \
230 | <(printf "\n[SAN]\nsubjectAltName=%s" "$4")) \
231 | -key "$KEY" \
232 | -new -sha256 -out "$CSR" -passin fd:3
233 | else
234 | openssl req -config "$INTRMDT_CONF" \
235 | -key "$KEY" \
236 | -new -sha256 -out "$CSR" -passin fd:3
237 | fi &&
238 | sign "$1" "$CSR" "$CERT" || {
239 | echoc 'Could not create certificate' red >&2
240 | return 1
241 | }
242 | echo
243 | echoc "Successfully created the following files" greenbold
244 | echo "Key: $KEY" | indent
245 | echo "Certificate: $CERT" | indent
246 | }
247 |
248 | create-intermediate() {
249 | # https://jamielinux.com/docs/openssl-certificate-authority/create-the-intermediate-pair.html
250 | echoc 'Creating intermediate CA private key' green
251 | INTRMDT_PASS=$(get-password 'intermediate CA private key')
252 | exec 3<<<"$INTRMDT_PASS"
253 | openssl genrsa -aes256 -out "$INTRMDT_KEY" -passout "fd:3" 4096 |& indent &&
254 | chmod 400 "$INTRMDT_KEY" || {
255 | echoc 'Could not create intermediate CA private key' red >&2
256 | return 1
257 | }
258 |
259 | exec 3<<<"$INTRMDT_PASS"
260 | echoc 'Creating intermediate CA CSR' green &&
261 | openssl req -verbose -config "$INTRMDT_CONF" -new -sha256 \
262 | -key "$INTRMDT_KEY" \
263 | -out "$INTRMDT_CSR" -passin "fd:3" || {
264 | echoc 'Could not create intermediate CA CSR' red >&2
265 | return 1
266 | }
267 |
268 | if [[ -n $ROOT_PASS ]]; then
269 | exec 3<<<"$ROOT_PASS"
270 | PASS_ARGS=(-passin "fd:3")
271 | fi
272 | echoc 'Signing intermediate CA CSR' green &&
273 | openssl ca -config "$ROOT_CONF" -extensions v3_intermediate_ca \
274 | -days 3650 -notext -md sha256 \
275 | -in "$INTRMDT_CSR" \
276 | -out "$INTRMDT_CERT" "${PASS_ARGS[@]}" &&
277 | chmod 444 "$INTRMDT_CERT" || {
278 | echoc 'Could not sign intermediate CA CSR' red >&2
279 | return 1
280 | }
281 |
282 | echoc 'Verifying intermediate CA cert' green
283 | openssl x509 -noout -text -in "$INTRMDT_CERT" | remove_openssl_hex | indent ||
284 | {
285 | echoc 'Could not verify intermediate CA certificate' red >&2
286 | return 1
287 | }
288 | echoc 'Press any key to continue...' yellow | indent
289 | read -n1 -r -s
290 |
291 | generate-crl || return 1
292 |
293 | verify-intermediate || return 1
294 |
295 | echoc "Successfully created the following files" greenbold
296 | echo "Key: $INTRMDT_KEY" | indent
297 | echo "Certificate: $INTRMDT_CERT" | indent
298 | if [[ -n $INTRMDT_CRL_DP ]]; then
299 | echo "CRL: $INTRMDT_CRL" | indent
300 | fi
301 | }
302 |
303 | sign() {
304 | # https://jamielinux.com/docs/openssl-certificate-authority/sign-server-and-client-certificates.html
305 | if [[ "$1" == "server" ]]; then
306 | EXT='server_cert'
307 | elif [[ "$1" == "client_server" ]]; then
308 | EXT='client_server_cert'
309 | else
310 | EXT='usr_cert'
311 | fi
312 | CSR="$2"
313 | CERT="$3"
314 | echoc 'Signing certificate' green
315 | INTRMDT_PASS=$(get-password 'intermediate CA private key' -noverify)
316 | exec 3<<<"$INTRMDT_PASS"
317 | openssl ca -verbose -config "$INTRMDT_CONF" \
318 | -extensions $EXT -days 375 -notext -md sha256 \
319 | -in "$CSR" \
320 | -out "$CERT" -passin fd:3 &&
321 | chmod 444 "$CERT" || {
322 | echoc 'Could not sign certificate' red >&2
323 | return 1
324 | }
325 |
326 | verify "$CERT" || return 1
327 |
328 | echo
329 | echoc "Successfully signed $2 with $1 extensions" greenbold
330 | echoc "Created $3" greenbold
331 | }
332 |
333 | verify-intermediate() {
334 | echoc 'Verifying intermediate CA chain of trust' green
335 | if [[ -n $INTRMDT_CRL_DP ]]; then
336 | CRL_ARGS=("-verbose" "-crl_check" "-crl_download")
337 | fi
338 | openssl verify -show_chain "${CRL_ARGS[@]}" -CAfile "$ROOT_CERT" \
339 | "$INTRMDT_CERT" | remove_openssl_hex | indent || {
340 | echoc 'Could not verify intermediate CA chain of trust' red >&2
341 | return 1
342 | }
343 | }
344 |
345 | verify() {
346 | CERT=$1
347 | echoc 'Verifying certificate' green
348 | openssl x509 -noout -text \
349 | -in "$CERT" | remove_openssl_hex | indent || {
350 | echoc 'Could not verify certificate' red >&2
351 | exit 1
352 | }
353 |
354 | echoc 'Press any key to continue...' yellow | indent
355 | read -n1 -r -s
356 |
357 | echoc 'Verifying certificate chain of trust' green
358 | if [[ -n $INTRMDT_CRL_DP ]]; then
359 | openssl verify -verbose -show_chain -crl_check -crl_download -CAfile "$CA_CHAIN" "$CERT" |& indent
360 | else
361 | openssl verify -CAfile "$CA_CHAIN" "$CERT" |& indent
362 | fi ||
363 | {
364 | echoc 'Could not verify certificate chain of trust' red >&2
365 | return 1
366 | }
367 | }
368 |
369 | truststore() {
370 | CERT=$INTRMDT_DIR/certs/ca-chain.cert.pem
371 | TRUSTSTORE=$INTRMDT_DIR/certs/"$1"_truststore.p12
372 |
373 | command -v keytool &>/dev/null || {
374 | echoc 'keytool command not found. You may need to install java' red >&2
375 | return 1
376 | }
377 |
378 | if [[ ! -r $CERT ]]; then
379 | echoc "Could not find '$1'" red >&2
380 | return 1
381 | else
382 | INTRMDT_PASS=$(get-password "truststore export")
383 | keytool -importcert -trustcacerts -storetype PKCS12 \
384 | -keystore "$TRUSTSTORE" \
385 | -alias ca -file "$CA_CHAIN" -noprompt <<<"$(echo -ne "$INTRMDT_PASS\n$INTRMDT_PASS")" &&
386 | chmod 444 "$TRUSTSTORE" ||
387 | {
388 | echoc "Could not create trustore $TRUSTSTORE" red >&2
389 | return 1
390 | }
391 | fi
392 | echoc "Created $TRUSTSTORE" greenbold
393 | }
394 |
395 | pkcs12() {
396 | echoc "Exporting keypair to pkcs12 format" green
397 | KEY=$INTRMDT_DIR/private/"$1".key.pem
398 | CERT=$INTRMDT_DIR/certs/"$1".cert.pem
399 | P12=$INTRMDT_DIR/certs/"$1".p12
400 | if [[ ! -r $CERT || ! -r $KEY ]]; then
401 | echoc "Could not find '$1'" red >&2
402 | return 1
403 | else
404 | P12_PASS=$(get-password "pkcs12 export")
405 | exec 3<<<"$P12_PASS"
406 | openssl pkcs12 -export -out "$P12" \
407 | -inkey "$KEY" -in "$CERT" \
408 | -passout fd:3 \
409 | -certfile "$CA_CHAIN" &&
410 | chmod 440 "$P12" || {
411 | echoc 'Could not export to pkcs12' red >&2
412 | return 1
413 | }
414 | fi
415 | echoc "Created $P12" greenbold
416 | }
417 |
418 | list() {
419 | awk 'BEGIN { FS="\t" }
420 | {
421 | printf "\033[0;32m" $6 "\033[0m\n";
422 | if ($1 == "V") print "\tStatus: Valid";
423 | if ($1 == "R") print "\tStatus: Revoked";
424 | if ($1 == "E") print "\tStatus: Expired";
425 | print "\tExpires: 20"substr($2,0,2)"-"substr($2,3,2)"-"substr($2,5,2)" "substr($2,7,2)":"substr($2,9,2)":"substr($2,11,2)" UTC";
426 | if ($1 == "R") {
427 | print "\tRevoked: 20"substr($3,0,2)"-"substr($3,3,2)"-"substr($3,5,2)" "substr($3,7,2)":"substr($3,9,2)":"substr($3,11,2) " UTC";
428 | print "\tRevocation reason: "substr($3,15);
429 | }
430 | print "\tSerial: "$4,"\n";
431 | }' \
432 | "$INTRMDT_DIR"/index.txt
433 | }
434 |
435 | revoke() {
436 | # https://jamielinux.com/docs/openssl-certificate-authority/certificate-revocation-lists.html#revoke-a-certificate
437 | confirm "Revoke $1" || return 0
438 | if [ ! -r "$1" ]; then
439 | echoc "$1 is not readable" >&2
440 | return 1
441 | fi
442 | if [[ -n $2 ]]; then
443 | REASON_ARGS=(-crl_reason "$2")
444 | fi
445 | INTRMDT_PASS=$(get-password 'intermediate CA private key' -noverify)
446 | exec 3<<<"$INTRMDT_PASS"
447 | openssl ca -config "$INTRMDT_CONF" \
448 | -revoke "$1" -passin fd:3 "${REASON_ARGS[@]}" || {
449 | echoc "Could not revoke $1" >&2
450 | return 1
451 | }
452 | generate-crl || return 1
453 | echo
454 | echoc "Successfully revoked $1" greenbold
455 | }
456 |
457 | revoke-intermediate() {
458 | # https://jamielinux.com/docs/openssl-certificate-authority/certificate-revocation-lists.html#revoke-a-certificate
459 | confirm "Revoke intermediate CA certificate" || return 0
460 | if [[ -n $1 ]]; then
461 | REASON_ARGS=(-crl_reason "$1")
462 | fi
463 | ROOT_PASS=$(get-password 'root CA private key' -noverify)
464 | exec 3<<<"$ROOT_PASS"
465 | openssl ca -config "$ROOT_CONF" \
466 | -revoke "$INTRMDT_CERT" -passin fd:3 "${REASON_ARGS[@]}" || {
467 | echoc 'Could not revoke intermediate CA certificate' red >&2
468 | return 1
469 | }
470 | generate-crl -rootca || return 1
471 | echo
472 | echoc 'Successfully revoked intermediate CA certificate' greenbold
473 | }
474 |
475 | list-crl() {
476 | if [[ -n $ROOT_CRL_DP ]]; then
477 | echoc 'Root CRL' green
478 | openssl crl -inform DER -in "$ROOT_CRL" -noout -text | remove_openssl_hex | indent
479 | fi
480 | if [[ -n $INTRMDT_CRL_DP ]]; then
481 | echoc 'Intermediate CRL' green
482 | openssl crl -inform DER -in "$INTRMDT_CRL" -noout -text | remove_openssl_hex | indent
483 | fi
484 | }
485 |
486 | generate-crl() {
487 | # https://jamielinux.com/docs/openssl-certificate-authority/certificate-revocation-lists.html
488 | # CRL formats changed to DER since that is expected by openssl verify
489 | if [[ "$1" == "-rootca" ]]; then
490 | if [[ -n $ROOT_CRL_DP ]]; then
491 | echoc 'Generating root CRL' green
492 | if [[ -z $ROOT_PASS ]]; then
493 | ROOT_PASS=$(get-password 'root CA private key' -noverify)
494 | fi
495 | exec 3<<<"$ROOT_PASS"
496 | openssl ca -config "$ROOT_CONF" \
497 | -gencrl -out "${ROOT_CRL/der/pem}" \
498 | -passin "fd:3" |& indent || {
499 | echoc 'Could not create root CRL' red >&2
500 | return 1
501 | }
502 |
503 | echoc 'Converting to DER' green
504 | openssl crl -in "${ROOT_CRL/der/pem}" \
505 | -outform DER -out "$ROOT_CRL" &&
506 | rm "${ROOT_CRL/der/pem}" || {
507 | echoc 'Could not convert to DER' red >&2
508 | return 1
509 | }
510 |
511 | echoc 'Verifying root CA CRL' green
512 | openssl crl -inform DER -in "$ROOT_CRL" -noout -text | remove_openssl_hex | indent
513 | echoc 'Press any key to continue...' yellow | indent
514 | read -n1 -r -s
515 | fi
516 | elif [[ -n $INTRMDT_CRL_DP ]]; then
517 | echoc 'Generating intermediate CRL' green
518 | if [[ -z $INTRMDT_PASS ]]; then
519 | INTRMDT_PASS=$(get-password 'intermediate CA private key' -noverify)
520 | fi
521 | exec 3<<<"$INTRMDT_PASS"
522 | openssl ca -config "$INTRMDT_CONF" \
523 | -gencrl -out "${INTRMDT_CRL/der/pem}" \
524 | -passin "fd:3" | indent || {
525 | echoc 'Could not create intermediate CRL' red >&2
526 | return 1
527 | }
528 |
529 | echoc 'Converting to DER' green
530 | openssl crl -in "${INTRMDT_CRL/der/pem}" \
531 | -outform DER -out "$INTRMDT_CRL" &&
532 | rm "${INTRMDT_CRL/der/pem}" || {
533 | echoc 'Could not convert to DER' red >&2
534 | return 1
535 | }
536 |
537 | echoc 'Verifying intermediate CRL' green
538 | openssl crl -inform DER -in "$INTRMDT_CRL" -noout -text | remove_openssl_hex | indent
539 | echoc 'Press any key to continue...' yellow | indent
540 | read -n1 -r -s
541 | fi
542 | }
543 |
544 | generate-ocsp() {
545 | # https://jamielinux.com/docs/openssl-certificate-authority/online-certificate-status-protocol.html
546 | if [[ "$1" == "-rootca" ]]; then
547 | if [[ -n $ROOT_OCSP ]]; then
548 | echoc 'Generating root OCSP key' green
549 | ROOT_OCSP_PASS=$(get-password 'root OCSP private key')
550 | exec 3<<<"$ROOT_OCSP_PASS"
551 | openssl genrsa -aes256 \
552 | -out "$ROOT_OCSP_KEY" -passout "fd:3" 4096 |& indent || {
553 | echoc 'Could not create root OCSP key' >&2
554 | return 1
555 | }
556 |
557 | echoc 'Generating root OCSP CSR' green
558 | exec 3<<<"$ROOT_OCSP_PASS"
559 | openssl req -config "$ROOT_CONF" -new -sha256 \
560 | -key "$ROOT_OCSP_KEY" \
561 | -out "$ROOT_OCSP_CSR" -passin "fd:3" || {
562 | echoc 'Could not create root OCSP CSR' red >&2
563 | return 1
564 | }
565 |
566 | echoc 'Signing root OCSP certificate' green
567 |
568 | if [[ -n $ROOT_PASS ]]; then
569 | exec 3<<<"$ROOT_PASS"
570 | PASS_ARGS=(-passin "fd:3")
571 | fi
572 | openssl ca -config "$ROOT_CONF" \
573 | -extensions ocsp -days 375 -notext -md sha256 \
574 | -in "$ROOT_OCSP_CSR" \
575 | -out "$ROOT_OCSP_CERT" "${PASS_ARGS[@]}" || {
576 | echoc 'Could not sign root OCSP certificate' red >&2
577 | return 1
578 | }
579 |
580 | echoc 'Verifying root OCSP certificate' green
581 | openssl x509 -in "$ROOT_OCSP_CERT" -noout -text | remove_openssl_hex | indent
582 | echoc 'Press any key to continue...' yellow | indent
583 | read -n1 -r -s
584 | fi
585 | elif [[ -n $INTRMDT_OCSP ]]; then
586 | echoc 'Generating intermediate OCSP key' green
587 | INTRMDT_OCSP_PASS=$(get-password 'intermediate OCSP private key')
588 | exec 3<<<"$INTRMDT_OCSP_PASS"
589 | openssl genrsa -aes256 \
590 | -out "$INTRMDT_OCSP_KEY" -passout "fd:3" 4096 |& indent || {
591 | echoc 'Could not create intermediate OCSP key' >&2
592 | return 1
593 | }
594 |
595 | exec 3<<<"$INTRMDT_OCSP_PASS"
596 | echoc 'Generating intermediate OCSP CSR' green
597 | openssl req -config "$INTRMDT_CONF" -new -sha256 \
598 | -key "$INTRMDT_OCSP_KEY" \
599 | -out "$INTRMDT_OCSP_CSR" -passin "fd:3" || {
600 | echoc 'Could not create intermediate OCSP CSR' red >&2
601 | return 1
602 | }
603 |
604 | echoc 'Signing intermediate OCSP certificate' green
605 | if [[ -n $INTRMDT_PASS ]]; then
606 | exec 3<<<"$INTRMDT_PASS"
607 | PASS_ARGS=(-passin "fd:3")
608 | fi
609 | openssl ca -config "$INTRMDT_CONF" \
610 | -extensions ocsp -days 375 -notext -md sha256 \
611 | -in "$INTRMDT_OCSP_CSR" \
612 | -out "$INTRMDT_OCSP_CERT" "${PASS_ARGS[@]}" || {
613 | echoc 'Could not sign intermediate OCSP certificate' red >&2
614 | return 1
615 | }
616 |
617 | echoc 'Verifying intermediate OCSP certificate' green
618 | openssl x509 -in "$INTRMDT_OCSP_CERT" -noout -text | remove_openssl_hex | indent
619 | echoc 'Press any key to continue...' yellow | indent
620 | read -n1 -r -s
621 | fi
622 | }
623 |
624 | ocsp-responder() {
625 | # https://jamielinux.com/docs/openssl-certificate-authority/online-certificate-status-protocol.html
626 | if [[ -n $ROOT_OCSP || -n "$INTRMDT_OCSP" ]]; then
627 | if [[ "$2" == "-rootca" ]]; then
628 | CA=$ROOT_CERT
629 | INDEX="$ROOT_DIR"/index.txt
630 | RKEY=$ROOT_OCSP_KEY
631 | RCERT=$ROOT_OCSP_CERT
632 | #PASS=$(get-password 'root OCSP private key' -noverify)
633 | else
634 | CA=$CA_CHAIN
635 | INDEX=$INTRMDT_DIR/index.txt
636 | RKEY=$INTRMDT_OCSP_KEY
637 | RCERT=$INTRMDT_OCSP_CERT
638 | #PASS=$(get-password 'intermediate OCSP private key' -noverify)
639 | fi
640 | # exec 3<<<"$PASS"
641 | # openssl ocsp does not yet support the -passin arg
642 | # see: https://github.com/openssl/openssl/issues/10682
643 | openssl ocsp -port "$1" -text \
644 | -index "$INDEX" \
645 | -CA "$CA" \
646 | -rkey "$RKEY" \
647 | -rsigner "$RCERT" || {
648 | echoc 'Could not start OCSP responder' red >&2
649 | return 1
650 | }
651 | else
652 | echoc 'OCSP is not configured' red >&2
653 | return 1
654 | fi
655 | }
656 |
657 | ocsp-query() {
658 | # https://jamielinux.com/docs/openssl-certificate-authority/online-certificate-status-protocol.html
659 | echoc 'Sending query' green
660 | openssl ocsp -CAfile "$1" \
661 | -url "$2" -resp_text \
662 | -issuer "$3" \
663 | -cert "$4" | remove_openssl_hex | indent || {
664 | echoc "Could not complete OCSP query" red >&2
665 | return 1
666 | }
667 | }
668 |
669 | update-config() {
670 | get-default-fields
671 | write-root-conf || return 1
672 | write-intermediate-conf || return 1
673 | if [[ -n $ROOT_CRL ]]; then
674 | generate-crl -rootca || return 1
675 | fi
676 | if [[ -n $INTRMDT_CRL ]]; then
677 | generate-crl || return 1
678 | fi
679 | if [[ -n $ROOT_OCSP ]]; then
680 | generate-ocsp -rootca || return 1
681 | fi
682 | if [[ -n $INTRMDT_OCSP ]]; then
683 | generate-ocsp || return 1
684 | fi
685 | }
686 |
687 | get-password() {
688 | PASS=0
689 | PASSV=1
690 | while [[ "$PASS" != "$PASSV" ]]; do
691 | echo -ne '\t' >&2
692 | echo -ne "\e[33mEnter $1 pass phrase:\e[0;0m" >&2
693 | read -s -r PASS
694 | if ((${#PASS} < 4)); then
695 | echo -ne '\n\t' >&2
696 | echoc 'Pass phrase must be at least 4 characters' red >&2
697 | continue
698 | fi
699 | if [[ "$2" == "-noverify" ]]; then
700 | echo >&2
701 | break
702 | fi
703 | echo -ne '\n\t' >&2
704 | echo -ne "\e[33mVerifying - Enter $1 pass phrase:\e[0;0m" >&2
705 | read -s -r PASSV
706 | if [[ "$PASS" != "$PASSV" ]]; then
707 | echo >&2
708 | echoc 'Pass phrases did not match' red | indent >&2
709 | fi
710 | echo >&2
711 | done
712 | echo -n "$PASS"
713 | }
714 |
715 | prep-directory() {
716 | for dir in certs crl csr newcerts private; do
717 | if [ ! -d "$1/$dir" ]; then
718 | mkdir "$1/$dir" >&/dev/null || {
719 | echoc "Could not create $1/$dir" red >&2
720 | return 1
721 | }
722 | fi
723 | done
724 | {
725 | chmod 700 "$1"/private &&
726 | touch "$1"/index.txt &&
727 | # Added
728 | touch "$1"/index.txt.attr &&
729 | echo 1000 >"$1"/serial &&
730 | echo 1000 >"$1"/crlnumber
731 | } 2>/dev/null || {
732 | echoc 'Could not create files' red >&2
733 | return 1
734 | }
735 | }
736 |
737 | get-from-env-or-read() {
738 | NAME=$1
739 |
740 | }
741 |
742 | get-default-fields() {
743 | echoc 'Please enter defaults for the following fields:' green
744 | echoc 'Enter "." to disable prompting of the field' yellow | indent
745 | echoc 'Leave it blank to prompt without a default' yellow | indent
746 | echo
747 |
748 | declare -a fieldNames
749 | fieldNames=(countryName stateOrProvinceName localityName organizationName organizationalUnitName emailAddress)
750 | declare -A fieldMap
751 | fieldMap=(
752 | [countryName]='Country Name (2 letter code)'
753 | [stateOrProvinceName]='State or Province Name'
754 | [localityName]='Locality Name'
755 | [organizationName]="Organization Names (organizationName), separated by ';'"
756 | [organizationalUnitName]='Organizational Unit Name'
757 | [emailAddress]='Email Address'
758 | )
759 |
760 | DEFAULT_FIELDS='commonName = Common Name'
761 | for i in "${fieldNames[@]}"; do
762 | NAME=$i
763 | DESC=${fieldMap[$i]}
764 | echoc -n "$DESC ($NAME): " yellow | indent
765 |
766 | VALUE_FROM_ENV=${!NAME}
767 | if [[ -n $VALUE_FROM_ENV ]]; then
768 | echoc "$VALUE_FROM_ENV (from environment)" green
769 | RESPONSE=$VALUE_FROM_ENV
770 | else
771 | read -r RESPONSE
772 | fi
773 |
774 | if [[ "$RESPONSE" != '.' ]]; then
775 | if [[ "$NAME" == 'organizationName' ]]; then
776 | IFS=';'
777 | orgNames="$RESPONSE"
778 | unset IFS
779 | orgCount=0
780 | for orgName in "${orgNames[@]}"; do
781 | DEFAULT_FIELDS+=$'\n'"${orgCount}.organizationName = Organization Name $orgCount"
782 | if [[ -n $orgName ]]; then
783 | DEFAULT_FIELDS+=$'\n'"${orgCount}.organizationName_default = $orgName"
784 | fi
785 | ((orgCount++))
786 | done
787 | else
788 | DEFAULT_FIELDS+=$'\n'"$NAME = $DESC"
789 | if [[ -n $RESPONSE ]]; then
790 | DEFAULT_FIELDS+=$'\n'"${NAME}_default = $RESPONSE"
791 | fi
792 | fi
793 | fi
794 | done
795 | }
796 |
797 | write-root-conf() {
798 | touch "$ROOT_CONF" >&/dev/null
799 | if [ ! -w "$ROOT_CONF" ]; then
800 | echoc "Could not write '$ROOT_CONF'" >&2
801 | return 1
802 | fi
803 | if [[ -n $ROOT_CRL_DP ]]; then
804 | CRLLINE="crlDistributionPoints = $ROOT_CRL_DP"
805 | fi
806 | if [[ -n $ROOT_OCSP ]]; then
807 | OCSPLINE="authorityInfoAccess = OCSP;$ROOT_OCSP"
808 | fi
809 | cat <<-EOF > "$ROOT_CONF" 2> /dev/null || { echoc "Could not write '$ROOT_CONF'" red >&2; return 1; }
810 | # OpenSSL root CA configuration file.
811 | # https://jamielinux.com/docs/openssl-certificate-authority/appendix/root-configuration-file.html
812 | [ ca ]
813 | # 'man ca'
814 | default_ca = CA_default
815 |
816 | [ CA_default ]
817 | # Directory and file locations.
818 | dir = $ROOT_DIR
819 | certs = \$dir/certs
820 | crl_dir = \$dir/crl
821 | new_certs_dir = \$dir/newcerts
822 | database = \$dir/index.txt
823 | serial = \$dir/serial
824 | RANDFILE = \$dir/private/.rand
825 |
826 | # The root key and root certificate.
827 | private_key = \$dir/private/$ROOT_PREFIX.key.pem
828 | certificate = \$dir/certs/$ROOT_PREFIX.cert.pem
829 |
830 | # For certificate revocation lists.
831 | crlnumber = \$dir/crlnumber
832 | crl = \$dir/crl/$ROOT_PREFIX.crl.pem
833 | crl_extensions = crl_ext
834 | default_crl_days = 1465
835 |
836 | # SHA-1 is deprecated, so use SHA-2 instead.
837 | default_md = sha256
838 |
839 | name_opt = ca_default
840 | cert_opt = ca_default
841 | default_days = 375
842 | preserve = no
843 | policy = policy_strict
844 | copy_extensions = copy
845 |
846 | [ policy_strict ]
847 | # The root CA should only sign intermediate certificates that match.
848 | # See the POLICY FORMAT section of 'man ca'.
849 | commonName = supplied
850 | countryName = match
851 | stateOrProvinceName = match
852 | localityName = match
853 | organizationName = match
854 | organizationalUnitName = optional
855 | emailAddress = optional
856 |
857 | [ policy_loose ]
858 | # Allow the intermediate CA to sign a more diverse range of certificates.
859 | # See the POLICY FORMAT section of the 'ca' man page.
860 | commonName = supplied
861 | countryName = optional
862 | stateOrProvinceName = optional
863 | localityName = optional
864 | organizationName = optional
865 | organizationalUnitName = optional
866 | emailAddress = optional
867 |
868 | [ req ]
869 | # Options for the 'req' tool ('man req').
870 | default_bits = 2048
871 | distinguished_name = req_distinguished_name
872 | string_mask = utf8only
873 |
874 | # SHA-1 is deprecated, so use SHA-2 instead.
875 | default_md = sha256
876 |
877 | # Extension to add when the -x509 option is used.
878 | x509_extensions = v3_ca
879 |
880 | [ req_distinguished_name ]
881 | # See .
882 | $DEFAULT_FIELDS
883 |
884 | [ v3_ca ]
885 | # Extensions for a typical CA ('man x509v3_config').
886 | subjectKeyIdentifier = hash
887 | authorityKeyIdentifier = keyid:always,issuer
888 | basicConstraints = critical, CA:true
889 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign
890 |
891 | [ v3_intermediate_ca ]
892 | # Extensions for a typical intermediate CA ('man x509v3_config').
893 | subjectKeyIdentifier = hash
894 | authorityKeyIdentifier = keyid:always,issuer
895 | basicConstraints = critical, CA:true, pathlen:0
896 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign
897 | $CRLLINE
898 | $OCSPLINE
899 |
900 | [ usr_cert ]
901 | # Extensions for client certificates ('man x509v3_config').
902 | basicConstraints = CA:FALSE
903 | nsCertType = client, email
904 | nsComment = "OpenSSL Generated Client Certificate"
905 | subjectKeyIdentifier = hash
906 | authorityKeyIdentifier = keyid,issuer
907 | keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
908 | extendedKeyUsage = clientAuth, emailProtection
909 |
910 | [ server_cert ]
911 | # Extensions for server certificates ('man x509v3_config').
912 | basicConstraints = CA:FALSE
913 | nsCertType = server
914 | nsComment = "OpenSSL Generated Server Certificate"
915 | subjectKeyIdentifier = hash
916 | authorityKeyIdentifier = keyid,issuer:always
917 | keyUsage = critical, digitalSignature, keyEncipherment
918 | extendedKeyUsage = serverAuth
919 |
920 | [ client_server_cert ]
921 | basicConstraints = CA:FALSE
922 | nsCertType = client, server
923 | nsComment = "OpenSSL Generated Server Certificate"
924 | subjectKeyIdentifier = hash
925 | authorityKeyIdentifier = keyid,issuer:always
926 | keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
927 | extendedKeyUsage = clientAuth, serverAuth
928 | $CRLLINE
929 | $OCSPLINE
930 |
931 | [ crl_ext ]
932 | # Extension for CRLs ('man x509v3_config').
933 | authorityKeyIdentifier=keyid:always
934 |
935 | [ ocsp ]
936 | # Extension for OCSP signing certificates ('man ocsp').
937 | basicConstraints = CA:FALSE
938 | subjectKeyIdentifier = hash
939 | authorityKeyIdentifier = keyid,issuer
940 | keyUsage = critical, digitalSignature
941 | extendedKeyUsage = critical, OCSPSigning
942 | EOF
943 | }
944 |
945 | write-intermediate-conf() {
946 | touch "$INTRMDT_CONF" >&/dev/null
947 | if [ ! -w "$INTRMDT_CONF" ]; then
948 | echoc "Could not write $INTRMDT_CONF"
949 | return 1
950 | fi
951 | if [[ -n $INTRMDT_CRL_DP ]]; then
952 | CRLLINE="crlDistributionPoints = $INTRMDT_CRL_DP"
953 | fi
954 | if [[ -n $INTRMDT_OCSP ]]; then
955 | OCSPLINE="authorityInfoAccess = OCSP;$INTRMDT_OCSP"
956 | fi
957 | cat <<-EOF > "$INTRMDT_CONF" 2> /dev/null || { echoc "Could not write '$INTRMDT_CONF'"; return 1; }
958 | # OpenSSL intermediate CA configuration file.
959 | # https://jamielinux.com/docs/openssl-certificate-authority/appendix/intermediate-configuration-file.html
960 | [ ca ]
961 | # 'man ca'
962 | default_ca = CA_default
963 |
964 | [ CA_default ]
965 | # Directory and file locations.
966 | dir = $INTRMDT_DIR
967 | certs = \$dir/certs
968 | crl_dir = \$dir/crl
969 | new_certs_dir = \$dir/newcerts
970 | database = \$dir/index.txt
971 | serial = \$dir/serial
972 | RANDFILE = \$dir/private/.rand
973 |
974 | # The root key and root certificate.
975 | private_key = \$dir/private/$INTRMDT_PREFIX.key.pem
976 | certificate = \$dir/certs/$INTRMDT_PREFIX.cert.pem
977 |
978 | # For certificate revocation lists.
979 | crlnumber = \$dir/crlnumber
980 | crl = \$dir/crl/$INTRMDT_PREFIX.crl.pem
981 | crl_extensions = crl_ext
982 | default_crl_days = 32
983 |
984 | # SHA-1 is deprecated, so use SHA-2 instead.
985 | default_md = sha256
986 |
987 | name_opt = ca_default
988 | cert_opt = ca_default
989 | default_days = 375
990 | preserve = no
991 | policy = policy_loose
992 | copy_extensions = copy
993 |
994 | [ policy_strict ]
995 | # The root CA should only sign intermediate certificates that match.
996 | # See the POLICY FORMAT section of 'man ca'.
997 | commonName = supplied
998 | countryName = match
999 | stateOrProvinceName = match
1000 | localityName = match
1001 | organizationName = match
1002 | organizationalUnitName = optional
1003 | emailAddress = optional
1004 |
1005 | [ policy_loose ]
1006 | # Allow the intermediate CA to sign a more diverse range of certificates.
1007 | # See the POLICY FORMAT section of the 'ca' man page.
1008 | commonName = supplied
1009 | countryName = optional
1010 | stateOrProvinceName = optional
1011 | localityName = optional
1012 | organizationName = optional
1013 | organizationalUnitName = optional
1014 | emailAddress = optional
1015 |
1016 | [ req ]
1017 | # Options for the 'req' tool ('man req').
1018 | default_bits = 2048
1019 | distinguished_name = req_distinguished_name
1020 | string_mask = utf8only
1021 |
1022 | # SHA-1 is deprecated, so use SHA-2 instead.
1023 | default_md = sha256
1024 |
1025 | # Extension to add when the -x509 option is used.
1026 | x509_extensions = v3_ca
1027 |
1028 | [ req_distinguished_name ]
1029 | # See .
1030 | $DEFAULT_FIELDS
1031 |
1032 | [ v3_ca ]
1033 | # Extensions for a typical CA ('man x509v3_config').
1034 | subjectKeyIdentifier = hash
1035 | authorityKeyIdentifier = keyid:always,issuer
1036 | basicConstraints = critical, CA:true
1037 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign
1038 |
1039 | [ v3_intermediate_ca ]
1040 | # Extensions for a typical intermediate CA ('man x509v3_config').
1041 | subjectKeyIdentifier = hash
1042 | authorityKeyIdentifier = keyid:always,issuer
1043 | basicConstraints = critical, CA:true, pathlen:0
1044 | keyUsage = critical, digitalSignature, cRLSign, keyCertSign
1045 |
1046 | [ usr_cert ]
1047 | # Extensions for client certificates ('man x509v3_config').
1048 | basicConstraints = CA:FALSE
1049 | nsCertType = client, email
1050 | nsComment = "OpenSSL Generated Client Certificate"
1051 | subjectKeyIdentifier = hash
1052 | authorityKeyIdentifier = keyid,issuer
1053 | keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
1054 | extendedKeyUsage = clientAuth, emailProtection
1055 | $CRLLINE
1056 | $OCSPLINE
1057 |
1058 | [ server_cert ]
1059 | # Extensions for server certificates ('man x509v3_config').
1060 | basicConstraints = CA:FALSE
1061 | nsCertType = server
1062 | nsComment = "OpenSSL Generated Server Certificate"
1063 | subjectKeyIdentifier = hash
1064 | authorityKeyIdentifier = keyid,issuer:always
1065 | keyUsage = critical, digitalSignature, keyEncipherment
1066 | extendedKeyUsage = serverAuth
1067 | $CRLLINE
1068 | $OCSPLINE
1069 |
1070 | [ client_server_cert ]
1071 | basicConstraints = CA:FALSE
1072 | nsCertType = client, server
1073 | nsComment = "OpenSSL Generated Server Certificate"
1074 | subjectKeyIdentifier = hash
1075 | authorityKeyIdentifier = keyid,issuer:always
1076 | keyUsage = critical, nonRepudiation, digitalSignature, keyEncipherment
1077 | extendedKeyUsage = clientAuth, serverAuth
1078 | $CRLLINE
1079 | $OCSPLINE
1080 |
1081 | [ crl_ext ]
1082 | # Extension for CRLs ('man x509v3_config').
1083 | authorityKeyIdentifier=keyid:always
1084 |
1085 | [ ocsp ]
1086 | # Extension for OCSP signing certificates ('man ocsp').
1087 | basicConstraints = CA:FALSE
1088 | subjectKeyIdentifier = hash
1089 | authorityKeyIdentifier = keyid,issuer
1090 | keyUsage = critical, digitalSignature
1091 | extendedKeyUsage = critical, OCSPSigning
1092 | EOF
1093 | }
1094 |
1095 | check-spki-integrity() {
1096 | if [ ! -d "$ROOT_DIR" ]; then
1097 | echoc "Could not read $ROOT_DIR" yellow >&2
1098 | return 1
1099 | fi
1100 | if [ ! -d "$INTRMDT_DIR" ]; then
1101 | echoc "Could not read $INTRMDT_DIR" yellow >&2
1102 | return 1
1103 | fi
1104 | for i in "$ROOT_CONF" "$ROOT_CERT" "$INTRMDT_CONF" "$INTRMDT_KEY" "$INTRMDT_CERT" "$CA_CHAIN"; do
1105 | if [ ! -r "$i" ]; then
1106 | echoc "Could not read $i" yellow >&2
1107 | return 1
1108 | fi
1109 | done
1110 | if [[ -n $INTRMDT_CRL_DP && ! -r "$INTRMDT_CRL" ]]; then
1111 | echoc "Could not read $INTRMDT_CRL" yellow >&2
1112 | return 1
1113 | fi
1114 | if [[ -n $ROOT_CRL_DP && ! -r "$ROOT_CRL" ]]; then
1115 | echoc "Could not read $ROOT_CRL" yellow >&2
1116 | return 1
1117 | fi
1118 | if [[ -n $INTRMDT_OCSP && ! -r "$INTRMDT_OCSP_KEY" ]]; then
1119 | echoc "Could not read $INTRMDT_OCSP_KEY" yellow >&2
1120 | return 1
1121 | fi
1122 | if [[ -n $ROOT_OCSP && ! -r "$ROOT_OCSP_KEY" ]]; then
1123 | echoc "Could not read $ROOT_OCSP_KEY" yellow >&2
1124 | return 1
1125 | fi
1126 | if [[ "$1" == "-rootca" && ! -r "$ROOT_KEY" ]]; then
1127 | echoc "Could not read $ROOT_KEY" yellow >&2
1128 | return 1
1129 | fi
1130 | }
1131 |
1132 | find-cert() {
1133 | if [[ -f "$1" && -r "$1" ]]; then
1134 | CERT="$1"
1135 | elif [[ -r $INTRMDT_DIR/certs/"$1".cert.pem ]]; then
1136 | CERT=$INTRMDT_DIR/certs/"$1".cert.pem
1137 | else
1138 | echoc "Could not find certificate '$1'" red >&2
1139 | return 1
1140 | fi
1141 | echo "$CERT"
1142 | }
1143 |
1144 | remove_openssl_hex() {
1145 | grep -vE '^[[:space:]]*([0-9a-f]{2}:)+([0-9a-f]{2})?[[:space:]]*$'
1146 | }
1147 |
1148 | confirm() {
1149 | echo -ne "\e[33m$1 (y/n)?\e[0;0m" | indent
1150 | read -r answer
1151 | if [[ "$answer" != "y" ]]; then
1152 | return 1
1153 | fi
1154 | }
1155 |
1156 | echoc() {
1157 | if [[ "$1" == "-n" ]]; then
1158 | NO_NEWLINE="-n"
1159 | shift
1160 | fi
1161 | case "$2" in
1162 | 'red')
1163 | CC='\e[31m'
1164 | ;;
1165 | 'green')
1166 | CC='\e[32m'
1167 | ;;
1168 | 'greenbold')
1169 | CC='\e[1;32m'
1170 | ;;
1171 | 'yellow')
1172 | CC='\e[33m'
1173 | ;;
1174 | *)
1175 | CC='\e[0m'
1176 | ;;
1177 | esac
1178 | echo $NO_NEWLINE -e "${CC}$1\e[0m"
1179 | }
1180 |
1181 | indent() {
1182 | sed "s/^/\t/"
1183 | }
1184 |
1185 | print_help() {
1186 | echo 'Usage:'
1187 | echo ' spki init'
1188 | echo ' spki create (server | user | client_server) [-SAN ]'
1189 | echo ' spki create-intermediate'
1190 | echo ' spki sign (server | user | client_server) '
1191 | echo ' spki list'
1192 | echo ' spki verify-intermediate'
1193 | echo ' spki verify (certificate | file-prefix)'
1194 | echo ' spki export-pkcs12 '
1195 | echo ' spki export-truststore '
1196 | echo ' spki revoke (certificate | file-prefix)'
1197 | echo ' spki revoke-intermediate'
1198 | echo ' spki list-crl'
1199 | echo ' spki generate-crl [-rootca]'
1200 | echo ' spki generate-ocsp [-rootca]'
1201 | echo ' spki ocsp-responder [-rootca]'
1202 | echo ' spki ocsp-query (certificate | file-prefix) [-rootca]'
1203 | echo ' spki update-config'
1204 | }
1205 | COMMAND=$1
1206 | shift
1207 | case "$COMMAND" in
1208 | 'init')
1209 | init || exit 1
1210 | ;;
1211 | 'create')
1212 | if [[ "$1" != 'server' && "$1" != 'user' && "$1" != 'client_server' || ($# -eq 4 && ("$3" != '-SAN' || -z "$4")) || $# -lt 2 ]]; then
1213 | print_help
1214 | exit 1
1215 | fi
1216 | check-spki-integrity || {
1217 | echoc 'Could not verify spki root folder integrity' red >&2
1218 | exit 1
1219 | }
1220 | create "$@" || exit 1
1221 | ;;
1222 | 'create-intermediate')
1223 | check-spki-integrity || {
1224 | echoc 'Could not verify spki root folder integrity' red >&2
1225 | exit 1
1226 | }
1227 | create-intermediate || exit 1
1228 | ;;
1229 | 'sign')
1230 | if [[ $# -ne 3 || ("$1" != 'server' && "$1" != 'user' && "$1" != 'client_server') ]]; then
1231 | print_help
1232 | exit 1
1233 | fi
1234 | check-spki-integrity || {
1235 | echoc 'Could not verify spki root folder integrity' red >&2
1236 | exit 1
1237 | }
1238 | sign "$1" "$2" "$3" || exit 1
1239 | ;;
1240 | 'list')
1241 | list
1242 | ;;
1243 | 'verify-intermediate')
1244 | check-spki-integrity || {
1245 | echoc 'Could not verify spki root folder integrity' red >&2
1246 | exit 1
1247 | }
1248 | verify-intermediate || exit 1
1249 | ;;
1250 | 'verify')
1251 | check-spki-integrity || {
1252 | echoc 'Could not verify spki root folder integrity' red >&2
1253 | exit 1
1254 | }
1255 | CERT=$(find-cert "$1") || exit 1
1256 | verify "$CERT" || exit 1
1257 | ;;
1258 | 'export-pkcs12')
1259 | check-spki-integrity || {
1260 | echoc 'Could not verify spki root folder integrity' red >&2
1261 | exit 1
1262 | }
1263 | pkcs12 "$1" || exit 1
1264 | ;;
1265 | 'export-truststore')
1266 | check-spki-integrity || {
1267 | echoc 'Could not verify spki root folder integrity' red >&2
1268 | exit 1
1269 | }
1270 | truststore "$1" || exit 1
1271 | ;;
1272 | 'revoke')
1273 | check-spki-integrity || {
1274 | echoc 'Could not verify spki root folder integrity' red >&2
1275 | exit 1
1276 | }
1277 | CERT=$(find-cert "$1") || exit 1
1278 | revoke "$CERT" "$2" || exit 1
1279 | ;;
1280 | 'revoke-intermediate')
1281 | check-spki-integrity -rootca || {
1282 | echoc 'Could not verify spki root folder integrity' red >&2
1283 | exit 1
1284 | }
1285 | revoke-intermediate "$1" || exit 1
1286 | ;;
1287 | 'list-crl')
1288 | check-spki-integrity || {
1289 | echoc 'Could not verify spki root folder integrity' red >&2
1290 | exit 1
1291 | }
1292 | list-crl || exit 1
1293 | ;;
1294 | 'generate-crl')
1295 | check-spki-integrity "$1" || {
1296 | echoc 'Could not verify spki root folder integrity' red >&2
1297 | exit 1
1298 | }
1299 | generate-crl "$1" || exit 1
1300 | ;;
1301 | 'generate-ocsp')
1302 | check-spki-integrity "$1" || {
1303 | echoc 'Could not verify spki root folder integrity' red >&2
1304 | exit 1
1305 | }
1306 | generate-ocsp "$1" || exit 1
1307 | ;;
1308 | 'ocsp-responder')
1309 | if [[ $# -lt 1 || $# -gt 2 || $# == 2 && "$2" != "-rootca" ]]; then
1310 | print_help
1311 | exit 1
1312 | fi
1313 | check-spki-integrity "$2" || {
1314 | echoc 'Could not verify spki root folder integrity' red >&2
1315 | exit 1
1316 | }
1317 | ocsp-responder "$1" "$2" || exit 1
1318 | ;;
1319 | 'ocsp-query')
1320 | if [[ $# -nt 2 || $# -gt 3 || $# == 3 && "$3" != "-rootca" ]]; then
1321 | print_help
1322 | exit 1
1323 | fi
1324 | check-spki-integrity "$3" || {
1325 | echoc 'Could not verify spki root folder integrity' red >&2
1326 | exit 1
1327 | }
1328 | CERT=$(find-cert "$2") || exit 1
1329 | if [[ "$3" == "-rootca" ]]; then
1330 | ocsp-query "$ROOT_CERT" "$1" "$ROOT_CERT" "$CERT" || exit 1
1331 | else
1332 | ocsp-query "$CA_CHAIN" "$1" "$INTRMDT_CERT" "$CERT" || exit 1
1333 | fi
1334 | ;;
1335 | 'update-config')
1336 | update-config || exit 1
1337 | ;;
1338 | *)
1339 | print_help
1340 | exit 1
1341 | ;;
1342 | esac
1343 |
--------------------------------------------------------------------------------
/test/config:
--------------------------------------------------------------------------------
1 | ROOT_DIR=/tmp/spki/
2 | ROOT_PREFIX='ca_filetest'
3 | INTRMDT_PREFIX='intermediate_filetest'
--------------------------------------------------------------------------------
/test/test.bats:
--------------------------------------------------------------------------------
1 | # Some tests require http-server
2 | # npm install http-server -g
3 |
4 | load test_helpers
5 |
6 | setup() {
7 | load_vars
8 | export SPKI_ROOT_DIR="/tmp/spki"
9 | }
10 |
11 | teardown() {
12 | cleanup
13 | }
14 |
15 | @test "invoking spki without arguments prints usage" {
16 | run ./spki
17 | dump_output_on_fail
18 | [ "$status" -eq 1 ]
19 | [ "${lines[0]}" = "Usage:" ]
20 | }
21 |
22 | @test "init creates a root and intermediate cert with the right DNs" {
23 | run init_from_input
24 | dump_output_on_fail
25 | [ "$status" -eq 0 ]
26 |
27 | ROOTCERT=$(openssl x509 -in /tmp/spki/certs/ca.cert.pem -noout -text)
28 | echo "$ROOTCERT" | grep "Issuer: $ROOT_DN" &> /dev/null
29 | echo "$ROOTCERT" | grep "Subject: $ROOT_DN" &> /dev/null
30 | INTRMDTCERT=$(openssl x509 -in /tmp/spki/intermediate/certs/intermediate.cert.pem -noout -text)
31 | echo "$INTRMDTCERT" | grep "Issuer: $ROOT_DN" &> /dev/null
32 | echo "$INTRMDTCERT" | grep "Subject: $INTERMEDIATE_DN" &> /dev/null
33 | }
34 |
35 | @test "init with config file overwrites file and env vars" {
36 | export SPKI_CONFIG_FILE="test/config"
37 | export SPKI_ROOT_PREFIX="test"
38 | run init_from_input
39 | dump_output_on_fail
40 | [ "$status" -eq 0 ]
41 | [ -f /tmp/spki/certs/ca_filetest.cert.pem ]
42 | [ -f /tmp/spki/private/ca_filetest.key.pem ]
43 | [ -f /tmp/spki/intermediate/certs/intermediate_filetest.cert.pem ]
44 | [ -f /tmp/spki/intermediate/private/intermediate_filetest.key.pem ]
45 | }
46 |
47 | @test "conf defaults get set properly from user input" {
48 | run init_from_input
49 | dump_output_on_fail
50 | [ "$status" -eq 0 ]
51 |
52 | read -d '' CONF_DEFS <<-EOF || true
53 | commonName = Common Name
54 | countryName = Country Name (2 letter code)
55 | countryName_default = PL
56 | stateOrProvinceName = State or Province Name
57 | stateOrProvinceName_default = Warsaw
58 | localityName = Locality Name
59 | localityName_default = Warsaw
60 | 0.organizationName = Organization Name 0
61 | 0.organizationName_default = Company Ltd
62 | organizationalUnitName = Organizational Unit Name
63 | organizationalUnitName_default = Developers
64 | emailAddress = Email Address
65 | emailAddress_default = mail@company.com
66 | EOF
67 |
68 | # These tests check that all lines of $CONF_DEFS exist in openssl.cnfs
69 | ! diff /tmp/spki/openssl.cnf <(echo "$CONF_DEFS") | grep -E "^>"
70 | ! diff /tmp/spki/intermediate/openssl.cnf <(echo "$CONF_DEFS") | grep -E "^>"
71 | }
72 |
73 | @test "conf defaults get set properly from env vars" {
74 | export SPKI_countryName=US
75 | export SPKI_stateOrProvinceName=CA
76 | export SPKI_localityName=SoCal
77 | export SPKI_organizationalUnitName=Testers
78 | export SPKI_organizationName=Company\ Ltd\ Inc
79 | export SPKI_emailAddress=mail@companyltdinc.com
80 | #Intermediate DN must match Root
81 | INTERMEDIATE_COUNTRY_NAME="$SPKI_countryName"
82 | INTERMEDIATE_PROVINCE_NAME="$SPKI_stateOrProvinceName"
83 | INTERMEDIATE_LOCALITY_NAME="$SPKI_localityName"
84 | INTERMEDIATE_ORGANIZATION_NAME="$SPKI_organizationName"
85 | INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME="$SPKI_organizationalUnitName"
86 | INTERMEDIATE_MAIL="$SPKI_emailAddress"
87 |
88 | run init_from_envvars
89 | dump_output_on_fail
90 | [ "$status" -eq 0 ]
91 | read -d '' CONF_DEFS <<-EOF || true
92 | commonName = Common Name
93 | countryName = Country Name (2 letter code)
94 | countryName_default = US
95 | stateOrProvinceName = State or Province Name
96 | stateOrProvinceName_default = CA
97 | localityName = Locality Name
98 | localityName_default = SoCal
99 | 0.organizationName = Organization Name 0
100 | 0.organizationName_default = Company Ltd Inc
101 | organizationalUnitName = Organizational Unit Name
102 | organizationalUnitName_default = Testers
103 | emailAddress = Email Address
104 | emailAddress_default = mail@companyltdinc.com
105 | EOF
106 |
107 | # These tests check that all lines of $CONF_DEFS exist in openssl.cnfs
108 | ! diff /tmp/spki/openssl.cnf <(echo "$CONF_DEFS") | grep -E "^>"
109 | ! diff /tmp/spki/intermediate/openssl.cnf <(echo "$CONF_DEFS") | grep -E "^>"
110 | }
111 |
112 | @test "create server certificate" {
113 | init_from_input
114 | dump_output_on_fail
115 | run create server test
116 | [ "$status" -eq 0 ]
117 | [ -f "/tmp/spki/intermediate/private/test.key.pem" ]
118 | [ -f "/tmp/spki/intermediate/certs/test.cert.pem" ]
119 |
120 | # Check for correct DNs
121 | CERT=$(openssl x509 -in /tmp/spki/intermediate/certs/test.cert.pem -noout -text)
122 | echo "$CERT" | grep "Issuer: $INTERMEDIATE_DN" &> /dev/null
123 | echo "$CERT" | grep "Subject: $CERT_DN" &> /dev/null
124 |
125 | # Check for correct extensions
126 | read -d '' EXTENSIONS <<-EOF || true
127 | Netscape Cert Type:
128 | SSL Server
129 | X509v3 Key Usage: critical
130 | Digital Signature, Key Encipherment
131 | X509v3 Extended Key Usage:
132 | TLS Web Server Authentication
133 | EOF
134 |
135 | ! diff -Z <(echo "$CERT" | sed 's/^[ \t]*//') <(echo "$EXTENSIONS") | grep -E "^>"
136 | }
137 |
138 | @test "create user certificate" {
139 | init_from_input
140 |
141 | run create user test
142 | dump_output_on_fail
143 | [ "$status" -eq 0 ]
144 | [ -f "/tmp/spki/intermediate/private/test.key.pem" ]
145 | [ -f "/tmp/spki/intermediate/certs/test.cert.pem" ]
146 |
147 | # Check for correct DNs
148 | CERT=$(openssl x509 -in /tmp/spki/intermediate/certs/test.cert.pem -noout -text)
149 | echo "$CERT" | grep "Issuer: $INTERMEDIATE_DN" &> /dev/null
150 | echo "$CERT" | grep "Subject: $CERT_DN" &> /dev/null
151 |
152 | # Check for correct extensions
153 | read -d '' EXTENSIONS <<-EOF || true
154 | Netscape Cert Type:
155 | SSL Client, S/MIME
156 | X509v3 Key Usage: critical
157 | Digital Signature, Non Repudiation, Key Encipherment
158 | X509v3 Extended Key Usage:
159 | TLS Web Client Authentication, E-mail Protection
160 | EOF
161 |
162 | ! diff -Z <(echo "$CERT" | sed 's/^[ \t]*//') <(echo "$EXTENSIONS") | grep -E "^>"
163 | }
164 |
165 | @test "create client_server certificate" {
166 | init_from_input
167 |
168 | run create client_server test
169 | dump_output_on_fail
170 | [ "$status" -eq 0 ]
171 | [ -f "/tmp/spki/intermediate/private/test.key.pem" ]
172 | [ -f "/tmp/spki/intermediate/certs/test.cert.pem" ]
173 |
174 | # Check for correct DNs
175 | CERT=$(openssl x509 -in /tmp/spki/intermediate/certs/test.cert.pem -noout -text)
176 | echo "$CERT" | grep "Issuer: $INTERMEDIATE_DN" &> /dev/null
177 | echo "$CERT" | grep "Subject: $CERT_DN" &> /dev/null
178 |
179 | # Check for correct extensions
180 | read -d '' EXTENSIONS <<-EOF || true
181 | Netscape Cert Type:
182 | SSL Client, SSL Server
183 | X509v3 Key Usage: critical
184 | Digital Signature, Non Repudiation, Key Encipherment
185 | X509v3 Extended Key Usage:
186 | TLS Web Client Authentication, TLS Web Server Authentication
187 | EOF
188 | ! diff -Z <(echo "$CERT" | sed 's/^[ \t]*//') <(echo "$EXTENSIONS") | grep -E "^>"
189 | }
190 |
191 | @test "verify" {
192 | init_from_input
193 |
194 | create client_server test
195 |
196 | run ./spki verify test<<<"$ANYKEY"
197 | dump_output_on_fail
198 | [ "$status" -eq 0 ] # by prefix
199 |
200 | run ./spki verify "/tmp/spki/intermediate/certs/test.cert.pem"<<<"$ANYKEY"
201 | dump_output_on_fail
202 | [ "$status" -eq 0 ] # by filename
203 | }
204 |
205 | @test "sign" {
206 | init_from_input
207 | create_csr
208 |
209 | CERT="/tmp/spki/intermediate/certs/test.cert.pem"
210 | run ./spki sign client_server "$CSR" "$CERT" <<-EOF
211 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
212 | $YES
213 | $YES
214 | $ANYKEY
215 | EOF
216 | dump_output_on_fail
217 | [ "$status" -eq 0 ]
218 | [ -f "/tmp/spki/intermediate/certs/test.cert.pem" ]
219 | }
220 |
221 | @test "export to pkcs12" {
222 | init_from_input
223 | create client_server test
224 |
225 | run ./spki export-pkcs12 test <<-EOF
226 | $PRIVATE_KEY_PASSWORD
227 | $PRIVATE_KEY_PASSWORD
228 | EOF
229 | dump_output_on_fail
230 | [ "$status" -eq 0 ]
231 | [ -f "/tmp/spki/intermediate/certs/test.p12" ]
232 | }
233 |
234 | @test "export to trust store" {
235 | command -v keytool
236 | init_from_input
237 | create client_server test
238 |
239 | run ./spki export-truststore test <<-EOF
240 | $PRIVATE_KEY_PASSWORD
241 | $PRIVATE_KEY_PASSWORD
242 | EOF
243 | dump_output_on_fail
244 | [ "$status" -eq 0 ]
245 | [ -f "/tmp/spki/intermediate/certs/test_truststore.p12" ]
246 | }
247 |
248 | @test "list" {
249 | init_from_input
250 | create client_server test
251 |
252 | run ./spki list
253 | dump_output_on_fail
254 | [ "$status" -eq 0 ]
255 | # Bash test + regex avoids whitespace issues
256 | [[ "${lines[0]}" =~ "/CN=$CERT_COMMON_NAME/C=$INTERMEDIATE_COUNTRY_NAME/ST=$INTERMEDIATE_PROVINCE_NAME/L=$INTERMEDIATE_LOCALITY_NAME/O=$INTERMEDIATE_ORGANIZATION_NAME/OU=$INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME/emailAddress=$INTERMEDIATE_MAIL" ]]
257 | [[ "${lines[1]}" =~ "Status: Valid" ]]
258 | [[ "${lines[3]}" =~ "Serial: 1000" ]]
259 | }
260 |
261 | @test "generate crl" {
262 | start-http-server
263 | run init_from_input_crl
264 | dump_output_on_fail
265 | [ "$status" -eq 0 ]
266 | [ -f "/tmp/spki/crl/ca.crl.der" ]
267 | [ -f "/tmp/spki/intermediate/crl/intermediate.crl.der" ]
268 |
269 | run ./spki generate-crl <<-EOF
270 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
271 |
272 | $ANYKEY
273 | EOF
274 | dump_output_on_fail
275 | [ "$status" -eq 0 ]
276 |
277 | run ./spki generate-crl -rootca <<-EOF
278 | $ROOT_PRIVATE_KEY_PASSWORD
279 |
280 | $ANYKEY
281 | EOF
282 | dump_output_on_fail
283 | [ "$status" -eq 0 ]
284 |
285 | kill-http-server
286 | }
287 |
288 | @test "list-crl" {
289 | start-http-server
290 | init_from_input_crl
291 | run ./spki list-crl
292 | dump_output_on_fail
293 | [ "$status" -eq 0 ]
294 | [[ "${lines[1]}" =~ "Certificate Revocation List (CRL):" ]]
295 | [[ "${lines[2]}" =~ "Version 2 (0x1)" ]]
296 | [[ "${lines[3]}" =~ "Signature Algorithm: sha256WithRSAEncryption" ]]
297 | [[ "${lines[4]}" =~ "Issuer: $ROOT_DN" ]]
298 |
299 | [[ "${lines[16]}" =~ "Certificate Revocation List (CRL):" ]]
300 | [[ "${lines[17]}" =~ "Version 2 (0x1)" ]]
301 | [[ "${lines[18]}" =~ "Signature Algorithm: sha256WithRSAEncryption" ]]
302 | [[ "${lines[19]}" =~ "Issuer: $INTERMEDIATE_DN" ]]
303 | kill-http-server
304 | }
305 |
306 | @test "create and revoke cert (crl)" {
307 | start-http-server
308 | init_from_input_crl
309 |
310 | run create client_server test
311 | dump_output_on_fail
312 | [ "$status" -eq 0 ]
313 |
314 | run revoke test
315 | dump_output_on_fail
316 | [ "$status" -eq 0 ]
317 |
318 | run ./spki verify test <<-EOF
319 | $ANYKEY
320 | EOF
321 | dump_output_on_fail
322 | [ "$status" -eq 1 ]
323 |
324 | run ./spki list
325 | dump_output_on_fail
326 | [ "$status" -eq 0 ]
327 | [[ "${lines[1]}" =~ "Status: Revoked" ]]
328 | [[ "${lines[4]}" =~ "Revocation reason: keyCompromise" ]]
329 |
330 | run ./spki list-crl
331 | dump_output_on_fail
332 | [ "$status" -eq 0 ]
333 | [[ "${lines[29]}" =~ "Serial Number: 1000" ]]
334 | [[ "${lines[33]}" =~ "Key Compromise" ]]
335 | kill-http-server
336 | }
337 |
338 | @test "revoke intermediate" {
339 | start-http-server
340 | init_from_input_crl
341 |
342 | run ./spki revoke-intermediate superseded <<-EOF
343 | $YES
344 | $ROOT_PRIVATE_KEY_PASSWORD
345 | $ANYKEY
346 | EOF
347 | dump_output_on_fail
348 | [ "$status" -eq 0 ]
349 |
350 | run ./spki list-crl
351 | dump_output_on_fail
352 | [ "$status" -eq 0 ]
353 | [[ "${lines[14]}" =~ "Serial Number: 1000" ]]
354 | [[ "${lines[18]}" =~ "Superseded" ]]
355 |
356 | # this doesn't actually check the CRL DP
357 | # since it looks it up in the local database first
358 | run ./spki verify-intermediate
359 | dump_output_on_fail
360 | [ "$status" -eq 1 ]
361 |
362 | kill-http-server
363 | }
364 |
365 | @test "generate ocsp signing pairs" {
366 | run init_from_input_ocsp
367 | dump_output_on_fail
368 | [ "$status" -eq 0 ]
369 | [ -f "/tmp/spki/certs/ca.ocsp.cert.pem" ]
370 | [ -f "/tmp/spki/intermediate/certs/intermediate.ocsp.cert.pem" ]
371 |
372 | ROOT_OCSP_CERT=$(openssl x509 -in /tmp/spki/certs/ca.ocsp.cert.pem -noout -text)
373 | echo "$ROOT_OCSP_CERT" | grep "Issuer: $ROOT_DN"
374 | echo "$ROOT_OCSP_CERT" | grep "Subject: $ROOT_OCSP_DN"
375 |
376 | INTERMEDIATE_OCSP_CERT=$(openssl x509 -in /tmp/spki/intermediate/certs/intermediate.ocsp.cert.pem -noout -text)
377 | echo "$INTERMEDIATE_OCSP_CERT" | grep "Issuer: $INTERMEDIATE_DN"
378 | echo "$INTERMEDIATE_OCSP_CERT" | grep "Subject: $INTERMEDIATE_OCSP_DN"
379 | }
380 |
381 | @test "ocsp responder" { #can't start the ocsp responder programmaticaly because there's no -passin arg
382 | skip
383 | init_from_input_ocsp
384 | ./spki ocsp-responder 12345 &> /dev/null & <<-EOF
385 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
386 | EOF
387 |
388 | create client_server test
389 | run ./spki ocsp-query http://localhost:12345 test
390 | dump_output_on_fail
391 | [ "$status" -eq 0 ]
392 |
393 | revoke test
394 | kill %%
395 | }
396 |
--------------------------------------------------------------------------------
/test/test_helpers.bash:
--------------------------------------------------------------------------------
1 | cleanup() {
2 | rm -rf /tmp/spki
3 |
4 | unset -v SPKI_CONFIG_FILE
5 | unset -v SPKI_ROOT_DIR
6 | unset -v SPKI_ROOT_PREFIX
7 | unset -v SPKI_INTRMDT_PREFIX
8 | unset -v SPKI_ROOT_CRL_DP
9 | unset -v SPKI_INTRMDT_CRL_DP
10 | unset -v SPKI_ROOT_OCSP
11 | unset -v SPKI_INTRMDT_OCSP
12 | unset -v SPKI_countryName
13 | unset -v SPKI_stateOrProvinceName
14 | unset -v SPKI_localityName
15 | unset -v SPKI_organizationalUnitName
16 | unset -v SPKI_organizationName
17 | unset -v SPKI_emailAddress
18 | }
19 |
20 | load_vars() {
21 | countryName=PL
22 | stateOrProvinceName=Warsaw
23 | localityName=Warsaw
24 | organizationalUnitName=Developers
25 | organizationName=Company\ Ltd
26 | emailAddress=mail@company.com
27 |
28 | ROOT_COMMON_NAME="Root CA"
29 | ROOT_COUNTRY_NAME="$countryName"
30 | ROOT_PROVINCE_NAME="$stateOrProvinceName"
31 | ROOT_LOCALITY_NAME="$localityName"
32 | ROOT_ORGANIZATION_NAME="$organizationName"
33 | ROOT_ORGANIZATIONAL_UNIT_NAME="$organizationalUnitName"
34 | ROOT_MAIL="$emailAddress"
35 |
36 | ROOT_DN="CN = $ROOT_COMMON_NAME, C = $ROOT_COUNTRY_NAME, ST = $ROOT_PROVINCE_NAME, L = $ROOT_LOCALITY_NAME, O = $ROOT_ORGANIZATION_NAME, OU = $ROOT_ORGANIZATIONAL_UNIT_NAME, emailAddress = $ROOT_MAIL"
37 |
38 | ROOT_OCSP_COMMON_NAME="Root CA OCSP"
39 | ROOT_OCSP_DN="CN = $ROOT_OCSP_COMMON_NAME, C = $ROOT_COUNTRY_NAME, ST = $ROOT_PROVINCE_NAME, L = $ROOT_LOCALITY_NAME, O = $ROOT_ORGANIZATION_NAME, OU = $ROOT_ORGANIZATIONAL_UNIT_NAME, emailAddress = $ROOT_MAIL"
40 |
41 | INTERMEDIATE_COMMON_NAME="Intermediate CA"
42 | INTERMEDIATE_COUNTRY_NAME="$countryName"
43 | INTERMEDIATE_PROVINCE_NAME="$stateOrProvinceName"
44 | INTERMEDIATE_LOCALITY_NAME="$localityName"
45 | INTERMEDIATE_ORGANIZATION_NAME="$organizationName"
46 | INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME="$organizationalUnitName"
47 | INTERMEDIATE_MAIL="$emailAddress"
48 |
49 | INTERMEDIATE_DN="CN = $INTERMEDIATE_COMMON_NAME, C = $INTERMEDIATE_COUNTRY_NAME, ST = $INTERMEDIATE_PROVINCE_NAME, L = $INTERMEDIATE_LOCALITY_NAME, O = $INTERMEDIATE_ORGANIZATION_NAME, OU = $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME, emailAddress = $INTERMEDIATE_MAIL"
50 |
51 | INTERMEDIATE_OCSP_COMMON_NAME="Intermediate CA OCSP"
52 | INTERMEDIATE_OCSP_DN="CN = $INTERMEDIATE_OCSP_COMMON_NAME, C = $INTERMEDIATE_COUNTRY_NAME, ST = $INTERMEDIATE_PROVINCE_NAME, L = $INTERMEDIATE_LOCALITY_NAME, O = $INTERMEDIATE_ORGANIZATION_NAME, OU = $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME, emailAddress = $INTERMEDIATE_MAIL"
53 |
54 | CERT_COMMON_NAME="Test Cert"
55 | CERT_DN="CN = $CERT_COMMON_NAME, C = $INTERMEDIATE_COUNTRY_NAME, ST = $INTERMEDIATE_PROVINCE_NAME, L = $INTERMEDIATE_LOCALITY_NAME, O = $INTERMEDIATE_ORGANIZATION_NAME, OU = $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME, emailAddress = $INTERMEDIATE_MAIL"
56 |
57 | ROOT_PRIVATE_KEY_PASSWORD="123456"
58 | INTERMEDIATE_PRIVATE_KEY_PASSWORD="123456"
59 | PRIVATE_KEY_PASSWORD="123456"
60 |
61 | ANYKEY="k"
62 | YES="y"
63 | }
64 |
65 | init_from_input() {
66 | ./spki init <<-EOF
67 | $ROOT_COUNTRY_NAME
68 | $ROOT_PROVINCE_NAME
69 | $ROOT_LOCALITY_NAME
70 | $ROOT_ORGANIZATION_NAME
71 | $ROOT_ORGANIZATIONAL_UNIT_NAME
72 | $ROOT_MAIL
73 | $ROOT_PRIVATE_KEY_PASSWORD
74 | $ROOT_PRIVATE_KEY_PASSWORD
75 | $ROOT_COMMON_NAME
76 |
77 |
78 |
79 |
80 |
81 |
82 | $ANYKEY$INTERMEDIATE_PRIVATE_KEY_PASSWORD
83 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
84 | $INTERMEDIATE_COMMON_NAME
85 | $INTERMEDIATE_COUNTRY_NAME
86 | $INTERMEDIATE_PROVINCE_NAME
87 | $INTERMEDIATE_LOCALITY_NAME
88 | $INTERMEDIATE_ORGANIZATION_NAME
89 | $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME
90 | $INTERMEDIATE_MAIL
91 | $YES
92 | $YES
93 | $ANYKEY
94 | EOF
95 | }
96 |
97 | init_from_input_crl() {
98 | export SPKI_ROOT_CRL_DP="URI:http://localhost:8080/crl/ca.crl.der"
99 | export SPKI_INTRMDT_CRL_DP="URI:http://localhost:8080/intermediate/crl/intermediate.crl.der"
100 |
101 | ./spki init <<-EOF
102 | $ROOT_COUNTRY_NAME
103 | $ROOT_PROVINCE_NAME
104 | $ROOT_LOCALITY_NAME
105 | $ROOT_ORGANIZATION_NAME
106 | $ROOT_ORGANIZATIONAL_UNIT_NAME
107 | $ROOT_MAIL
108 | $ROOT_PRIVATE_KEY_PASSWORD
109 | $ROOT_PRIVATE_KEY_PASSWORD
110 | $ROOT_COMMON_NAME
111 |
112 |
113 |
114 |
115 |
116 |
117 | $ANYKEY$ANYKEY$INTERMEDIATE_PRIVATE_KEY_PASSWORD
118 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
119 | $INTERMEDIATE_COMMON_NAME
120 | $INTERMEDIATE_COUNTRY_NAME
121 | $INTERMEDIATE_PROVINCE_NAME
122 | $INTERMEDIATE_LOCALITY_NAME
123 | $INTERMEDIATE_ORGANIZATION_NAME
124 | $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME
125 | $INTERMEDIATE_MAIL
126 | $YES
127 | $YES
128 | $ANYKEY$ANYKEY
129 | EOF
130 | }
131 |
132 | init_from_input_ocsp() {
133 | export SPKI_ROOT_OCSP="URI:http://localhost:12345"
134 | export SPKI_INTRMDT_OCSP="URI:http://localhost:12346"
135 |
136 | ./spki init <<-EOF
137 | $ROOT_COUNTRY_NAME
138 | $ROOT_PROVINCE_NAME
139 | $ROOT_LOCALITY_NAME
140 | $ROOT_ORGANIZATION_NAME
141 | $ROOT_ORGANIZATIONAL_UNIT_NAME
142 | $ROOT_MAIL
143 | $ROOT_PRIVATE_KEY_PASSWORD
144 | $ROOT_PRIVATE_KEY_PASSWORD
145 | $ROOT_COMMON_NAME
146 |
147 |
148 |
149 |
150 |
151 |
152 | $ANYKEY$INTERMEDIATE_PRIVATE_KEY_PASSWORD
153 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
154 | $INTERMEDIATE_COMMON_NAME
155 | $INTERMEDIATE_COUNTRY_NAME
156 | $INTERMEDIATE_PROVINCE_NAME
157 | $INTERMEDIATE_LOCALITY_NAME
158 | $INTERMEDIATE_ORGANIZATION_NAME
159 | $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME
160 | $INTERMEDIATE_MAIL
161 | $YES
162 | $YES
163 | $ANYKEY$ROOT_PRIVATE_KEY_PASSWORD
164 | $ROOT_PRIVATE_KEY_PASSWORD
165 | $ROOT_OCSP_COMMON_NAME
166 |
167 |
168 |
169 |
170 |
171 |
172 | $YES
173 | $YES
174 | $ANYKEY$INTERMEDIATE_PRIVATE_KEY_PASSWORD
175 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
176 | $INTERMEDIATE_OCSP_COMMON_NAME
177 |
178 |
179 |
180 |
181 |
182 |
183 | $YES
184 | $YES
185 | $ANYKEY
186 | EOF
187 | }
188 |
189 | init_from_envvars() {
190 | ./spki init <<-EOF
191 | $ROOT_PRIVATE_KEY_PASSWORD
192 | $ROOT_PRIVATE_KEY_PASSWORD
193 | $ROOT_COMMON_NAME
194 |
195 |
196 |
197 |
198 |
199 |
200 | $ANYKEY$INTERMEDIATE_PRIVATE_KEY_PASSWORD
201 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
202 | $INTERMEDIATE_COMMON_NAME
203 | $INTERMEDIATE_COUNTRY_NAME
204 | $INTERMEDIATE_PROVINCE_NAME
205 | $INTERMEDIATE_LOCALITY_NAME
206 | $INTERMEDIATE_ORGANIZATION_NAME
207 | $INTERMEDIATE_ORGANIZATIONAL_UNIT_NAME
208 | $INTERMEDIATE_MAIL
209 | $YES
210 | $YES
211 | $ANYKEY
212 | EOF
213 | }
214 |
215 | create() {
216 | ./spki create $@ <<-EOF
217 | $PRIVATE_KEY_PASSWORD
218 | $PRIVATE_KEY_PASSWORD
219 | $CERT_COMMON_NAME
220 |
221 |
222 |
223 |
224 |
225 |
226 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
227 | $YES
228 | $YES
229 | $ANYKEY
230 | EOF
231 | }
232 |
233 | create_csr() {
234 | INTRMDT_CONF="/tmp/spki/intermediate/openssl.cnf"
235 | KEY="/tmp/spki/intermediate/private/test.key.pem"
236 | CSR="/tmp/spki/intermediate/csr/test.csr.pem"
237 | PASS="123456"
238 | openssl genrsa -aes256 -out "$KEY" -passout "pass:$PASS" 4096
239 | openssl req -config "$INTRMDT_CONF" -key "$KEY" -new -sha256 -out "$CSR" -passin "pass:$PASS" <<-EOF
240 | $CERT_COMMON_NAME
241 |
242 |
243 |
244 |
245 |
246 |
247 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
248 | $YES
249 | $YES
250 | $ANYKEY
251 | EOF
252 | }
253 |
254 | revoke() {
255 | ./spki revoke $1 keyCompromise <<-EOF
256 | $YES
257 | $INTERMEDIATE_PRIVATE_KEY_PASSWORD
258 | $ANYKEY
259 | EOF
260 | }
261 |
262 | dump_output_on_fail() {
263 | for line in "${lines[@]}"; do echo "$line"; done
264 | echo "Status: $status"
265 | }
266 |
267 | start-http-server() {
268 | command -v http-server &> /dev/null
269 | http-server /tmp/spki &> /dev/null &
270 | HTTP_SERVER_PID=$!
271 | }
272 |
273 | kill-http-server() {
274 | kill $HTTP_SERVER_PID
275 | }
--------------------------------------------------------------------------------