pax_global_header00006660000000000000000000000064135362562240014522gustar00rootroot0000000000000052 comment=4c0b8ba055a8da47cdfad924ff69122ad97f660f pam_p11-pam_p11-0.3.1/000077500000000000000000000000001353625622400142155ustar00rootroot00000000000000pam_p11-pam_p11-0.3.1/.gitignore000066400000000000000000000022171353625622400162070ustar00rootroot00000000000000Makefile Makefile.in core archive acinclude.m4 aclocal.m4 autom4te.cache compile confdefs.h config.* configure conftest conftest.c depcomp install-sh libtool libtool.m4 ltmain.sh missing mkinstalldirs so_locations stamp-h* .deps .libs .#*# .*.bak .*.orig .*.rej .*~ #*# *.bak *.d *.def *.dll *.exe *.la *.lib *.lo *.o *.orig *.pdb *.rej *.u *.rc *.pc *~ *.gz *.bz2 *.out m4/ltoptions.m4 m4/ltsugar.m4 m4/ltversion.m4 m4/lt~obsolete.m4 src/test-login src/test-passwd ABOUT-NLS m4/codeset.m4 m4/extern-inline.m4 m4/fcntl-o.m4 m4/gettext.m4 m4/glibc2.m4 m4/glibc21.m4 m4/iconv.m4 m4/intdiv0.m4 m4/intl.m4 m4/intldir.m4 m4/intlmacosx.m4 m4/intmax.m4 m4/inttypes-pri.m4 m4/inttypes_h.m4 m4/lcmessage.m4 m4/lib-ld.m4 m4/lib-link.m4 m4/lib-prefix.m4 m4/lock.m4 m4/longlong.m4 m4/nls.m4 m4/po.m4 m4/printf-posix.m4 m4/progtest.m4 m4/size_max.m4 m4/stdint_h.m4 m4/threadlib.m4 m4/uintmax_t.m4 m4/visibility.m4 m4/wchar_t.m4 m4/wint_t.m4 m4/xsize.m4 po/Makefile.in.in po/Makevars.template po/Rules-quot po/boldquot.sed po/en@boldquot.header po/en@quot.header po/insert-header.sin po/quot.sed po/remove-potcdate.sin po/POTFILES po/stamp-po po/remove-potcdate.sed *.gmo *.mo pam_p11-pam_p11-0.3.1/.travis.yml000066400000000000000000000033261353625622400163320ustar00rootroot00000000000000language: c matrix: include: - compiler: clang os: osx - compiler: gcc os: linux - env: DO_COVERITY_SCAN=yes env: global: # The next declaration is the encrypted COVERITY_SCAN_TOKEN, created # via the "travis encrypt" command using the project repo's public key - secure: "ByZq6EUK5MXuqJIhI1xSu1cmi/P7lKRi476LrOLmOHhE+w7Go99YVFPeNH27eIROnRYzlYosloFknHxZ2vsJxAKMaQjmmqLASxGXw3hYcvCX2P9/WJaSagw8WenrcC0gFLNVljiYMEKqaBbldVuG8Bz+HpeyyDvm4TfShDic9Kw=" - COVERITY_SCAN_BRANCH_PATTERN="(master|coverity.*)" - COVERITY_SCAN_NOTIFICATION_EMAIL="frankmorgner@gmail.com" - COVERITY_SCAN_BUILD_COMMAND="make -j 4" - COVERITY_SCAN_PROJECT_NAME="$TRAVIS_REPO_SLUG" - SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) sudo: false addons: apt_packages: - libp11-dev - libssl-dev - libpam0g-dev - autopoint before_install: - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; brew uninstall libtool; brew install libtool; brew install libp11 openssl ccache; export CFLAGS="-I$(brew --prefix openssl)/include" export LDFLAGS="-L$(brew --prefix openssl)/lib" export PATH="/usr/local/opt/ccache/libexec:$PATH"; export PATH="/usr/local/opt/gettext/bin:$PATH"; fi before_script: - ./bootstrap - ./configure # Optionally try to upload to Coverity Scan # On error (propably quota is exhausted), just continue - if [ -n "${DO_COVERITY_SCAN}" ]; then curl -s 'https://scan.coverity.com/scripts/travisci_build_coverity_scan.sh' | bash || true; fi script: - if [ -z "${DO_COVERITY_SCAN}" ]; then make distcheck; fi cache: apt: true ccache: true directories: - $HOME/Library/Caches/Homebrew pam_p11-pam_p11-0.3.1/COPYING000066400000000000000000000634761353625622400152700ustar00rootroot00000000000000 GNU LESSER GENERAL PUBLIC LICENSE Version 2.1, February 1999 Copyright (C) 1991, 1999 Free Software Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. [This is the first released version of the Lesser GPL. It also counts as the successor of the GNU Library Public License, version 2, hence the version number 2.1.] Preamble The licenses for most software are designed to take away your freedom to share and change it. By contrast, the GNU General Public Licenses are intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. This license, the Lesser General Public License, applies to some specially designated software packages--typically libraries--of the Free Software Foundation and other authors who decide to use it. You can use it too, but we suggest you first think carefully about whether this license or the ordinary General Public License is the better strategy to use in any particular case, based on the explanations below. When we speak of free software, we are referring to freedom of use, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for this service if you wish); that you receive source code or can get it if you want it; that you can change the software and use pieces of it in new free programs; and that you are informed that you can do these things. To protect your rights, we need to make restrictions that forbid distributors to deny you these rights or to ask you to surrender these rights. These restrictions translate to certain responsibilities for you if you distribute copies of the library or if you modify it. For example, if you distribute copies of the library, whether gratis or for a fee, you must give the recipients all the rights that we gave you. You must make sure that they, too, receive or can get the source code. If you link other code with the library, you must provide complete object files to the recipients, so that they can relink them with the library after making changes to the library and recompiling it. And you must show them these terms so they know their rights. We protect your rights with a two-step method: (1) we copyright the library, and (2) we offer you this license, which gives you legal permission to copy, distribute and/or modify the library. To protect each distributor, we want to make it very clear that there is no warranty for the free library. Also, if the library is modified by someone else and passed on, the recipients should know that what they have is not the original version, so that the original author's reputation will not be affected by problems that might be introduced by others. Finally, software patents pose a constant threat to the existence of any free program. We wish to make sure that a company cannot effectively restrict the users of a free program by obtaining a restrictive license from a patent holder. Therefore, we insist that any patent license obtained for a version of the library must be consistent with the full freedom of use specified in this license. Most GNU software, including some libraries, is covered by the ordinary GNU General Public License. This license, the GNU Lesser General Public License, applies to certain designated libraries, and is quite different from the ordinary General Public License. We use this license for certain libraries in order to permit linking those libraries into non-free programs. When a program is linked with a library, whether statically or using a shared library, the combination of the two is legally speaking a combined work, a derivative of the original library. The ordinary General Public License therefore permits such linking only if the entire combination fits its criteria of freedom. The Lesser General Public License permits more lax criteria for linking other code with the library. We call this license the "Lesser" General Public License because it does Less to protect the user's freedom than the ordinary General Public License. It also provides other free software developers Less of an advantage over competing non-free programs. These disadvantages are the reason we use the ordinary General Public License for many libraries. However, the Lesser license provides advantages in certain special circumstances. For example, on rare occasions, there may be a special need to encourage the widest possible use of a certain library, so that it becomes a de-facto standard. To achieve this, non-free programs must be allowed to use the library. A more frequent case is that a free library does the same job as widely used non-free libraries. In this case, there is little to gain by limiting the free library to free software only, so we use the Lesser General Public License. In other cases, permission to use a particular library in non-free programs enables a greater number of people to use a large body of free software. For example, permission to use the GNU C Library in non-free programs enables many more people to use the whole GNU operating system, as well as its variant, the GNU/Linux operating system. Although the Lesser General Public License is Less protective of the users' freedom, it does ensure that the user of a program that is linked with the Library has the freedom and the wherewithal to run that program using a modified version of the Library. The precise terms and conditions for copying, distribution and modification follow. Pay close attention to the difference between a "work based on the library" and a "work that uses the library". The former contains code derived from the library, whereas the latter must be combined with the library in order to run. GNU LESSER GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any software library or other program which contains a notice placed by the copyright holder or other authorized party saying it may be distributed under the terms of this Lesser General Public License (also called "this License"). Each licensee is addressed as "you". A "library" means a collection of software functions and/or data prepared so as to be conveniently linked with application programs (which use some of those functions and data) to form executables. The "Library", below, refers to any such software library or work which has been distributed under these terms. A "work based on the Library" means either the Library or any derivative work under copyright law: that is to say, a work containing the Library or a portion of it, either verbatim or with modifications and/or translated straightforwardly into another language. (Hereinafter, translation is included without limitation in the term "modification".) "Source code" for a work means the preferred form of the work for making modifications to it. For a library, complete source code means all the source code for all modules it contains, plus any associated interface definition files, plus the scripts used to control compilation and installation of the library. Activities other than copying, distribution and modification are not covered by this License; they are outside its scope. The act of running a program using the Library is not restricted, and output from such a program is covered only if its contents constitute a work based on the Library (independent of the use of the Library in a tool for writing it). Whether that is true depends on what the Library does and what the program that uses the Library does. 1. You may copy and distribute verbatim copies of the Library's complete source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this License and to the absence of any warranty; and distribute a copy of this License along with the Library. You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. 2. You may modify your copy or copies of the Library or any portion of it, thus forming a work based on the Library, and copy and distribute such modifications or work under the terms of Section 1 above, provided that you also meet all of these conditions: a) The modified work must itself be a software library. b) You must cause the files modified to carry prominent notices stating that you changed the files and the date of any change. c) You must cause the whole of the work to be licensed at no charge to all third parties under the terms of this License. d) If a facility in the modified Library refers to a function or a table of data to be supplied by an application program that uses the facility, other than as an argument passed when the facility is invoked, then you must make a good faith effort to ensure that, in the event an application does not supply such function or table, the facility still operates, and performs whatever part of its purpose remains meaningful. (For example, a function in a library to compute square roots has a purpose that is entirely well-defined independent of the application. Therefore, Subsection 2d requires that any application-supplied function or table used by this function must be optional: if the application does not supply it, the square root function must still compute square roots.) These requirements apply to the modified work as a whole. If identifiable sections of that work are not derived from the Library, and can be reasonably considered independent and separate works in themselves, then this License, and its terms, do not apply to those sections when you distribute them as separate works. But when you distribute the same sections as part of a whole which is a work based on the Library, the distribution of the whole must be on the terms of this License, whose permissions for other licensees extend to the entire whole, and thus to each and every part regardless of who wrote it. Thus, it is not the intent of this section to claim rights or contest your rights to work written entirely by you; rather, the intent is to exercise the right to control the distribution of derivative or collective works based on the Library. In addition, mere aggregation of another work not based on the Library with the Library (or with a work based on the Library) on a volume of a storage or distribution medium does not bring the other work under the scope of this License. 3. You may opt to apply the terms of the ordinary GNU General Public License instead of this License to a given copy of the Library. To do this, you must alter all the notices that refer to this License, so that they refer to the ordinary GNU General Public License, version 2, instead of to this License. (If a newer version than version 2 of the ordinary GNU General Public License has appeared, then you can specify that version instead if you wish.) Do not make any other change in these notices. Once this change is made in a given copy, it is irreversible for that copy, so the ordinary GNU General Public License applies to all subsequent copies and derivative works made from that copy. This option is useful when you wish to copy part of the code of the Library into a program that is not a library. 4. You may copy and distribute the Library (or a portion or derivative of it, under Section 2) in object code or executable form under the terms of Sections 1 and 2 above provided that you accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Sections 1 and 2 above on a medium customarily used for software interchange. If distribution of object code is made by offering access to copy from a designated place, then offering equivalent access to copy the source code from the same place satisfies the requirement to distribute the source code, even though third parties are not compelled to copy the source along with the object code. 5. A program that contains no derivative of any portion of the Library, but is designed to work with the Library by being compiled or linked with it, is called a "work that uses the Library". Such a work, in isolation, is not a derivative work of the Library, and therefore falls outside the scope of this License. However, linking a "work that uses the Library" with the Library creates an executable that is a derivative of the Library (because it contains portions of the Library), rather than a "work that uses the library". The executable is therefore covered by this License. Section 6 states terms for distribution of such executables. When a "work that uses the Library" uses material from a header file that is part of the Library, the object code for the work may be a derivative work of the Library even though the source code is not. Whether this is true is especially significant if the work can be linked without the Library, or if the work is itself a library. The threshold for this to be true is not precisely defined by law. If such an object file uses only numerical parameters, data structure layouts and accessors, and small macros and small inline functions (ten lines or less in length), then the use of the object file is unrestricted, regardless of whether it is legally a derivative work. (Executables containing this object code plus portions of the Library will still fall under Section 6.) Otherwise, if the work is a derivative of the Library, you may distribute the object code for the work under the terms of Section 6. Any executables containing that work also fall under Section 6, whether or not they are linked directly with the Library itself. 6. As an exception to the Sections above, you may also combine or link a "work that uses the Library" with the Library to produce a work containing portions of the Library, and distribute that work under terms of your choice, provided that the terms permit modification of the work for the customer's own use and reverse engineering for debugging such modifications. You must give prominent notice with each copy of the work that the Library is used in it and that the Library and its use are covered by this License. You must supply a copy of this License. If the work during execution displays copyright notices, you must include the copyright notice for the Library among them, as well as a reference directing the user to the copy of this License. Also, you must do one of these things: a) Accompany the work with the complete corresponding machine-readable source code for the Library including whatever changes were used in the work (which must be distributed under Sections 1 and 2 above); and, if the work is an executable linked with the Library, with the complete machine-readable "work that uses the Library", as object code and/or source code, so that the user can modify the Library and then relink to produce a modified executable containing the modified Library. (It is understood that the user who changes the contents of definitions files in the Library will not necessarily be able to recompile the application to use the modified definitions.) b) Use a suitable shared library mechanism for linking with the Library. A suitable mechanism is one that (1) uses at run time a copy of the library already present on the user's computer system, rather than copying library functions into the executable, and (2) will operate properly with a modified version of the library, if the user installs one, as long as the modified version is interface-compatible with the version that the work was made with. c) Accompany the work with a written offer, valid for at least three years, to give the same user the materials specified in Subsection 6a, above, for a charge no more than the cost of performing this distribution. d) If distribution of the work is made by offering access to copy from a designated place, offer equivalent access to copy the above specified materials from the same place. e) Verify that the user has already received a copy of these materials or that you have already sent this user a copy. For an executable, the required form of the "work that uses the Library" must include any data and utility programs needed for reproducing the executable from it. However, as a special exception, the materials to be distributed need not include anything that is normally distributed (in either source or binary form) with the major components (compiler, kernel, and so on) of the operating system on which the executable runs, unless that component itself accompanies the executable. It may happen that this requirement contradicts the license restrictions of other proprietary libraries that do not normally accompany the operating system. Such a contradiction means you cannot use both them and the Library together in an executable that you distribute. 7. You may place library facilities that are a work based on the Library side-by-side in a single library together with other library facilities not covered by this License, and distribute such a combined library, provided that the separate distribution of the work based on the Library and of the other library facilities is otherwise permitted, and provided that you do these two things: a) Accompany the combined library with a copy of the same work based on the Library, uncombined with any other library facilities. This must be distributed under the terms of the Sections above. b) Give prominent notice with the combined library of the fact that part of it is a work based on the Library, and explaining where to find the accompanying uncombined form of the same work. 8. You may not copy, modify, sublicense, link with, or distribute the Library except as expressly provided under this License. Any attempt otherwise to copy, modify, sublicense, link with, or distribute the Library is void, and will automatically terminate your rights under this License. However, parties who have received copies, or rights, from you under this License will not have their licenses terminated so long as such parties remain in full compliance. 9. You are not required to accept this License, since you have not signed it. However, nothing else grants you permission to modify or distribute the Library or its derivative works. These actions are prohibited by law if you do not accept this License. Therefore, by modifying or distributing the Library (or any work based on the Library), you indicate your acceptance of this License to do so, and all its terms and conditions for copying, distributing or modifying the Library or works based on it. 10. Each time you redistribute the Library (or any work based on the Library), the recipient automatically receives a license from the original licensor to copy, distribute, link with or modify the Library subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. You are not responsible for enforcing compliance by third parties with this License. 11. If, as a consequence of a court judgment or allegation of patent infringement or for any other reason (not limited to patent issues), conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot distribute so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not distribute the Library at all. For example, if a patent license would not permit royalty-free redistribution of the Library by all those who receive copies directly or indirectly through you, then the only way you could satisfy both it and this License would be to refrain entirely from distribution of the Library. If any portion of this section is held invalid or unenforceable under any particular circumstance, the balance of the section is intended to apply, and the section as a whole is intended to apply in other circumstances. It is not the purpose of this section to induce you to infringe any patents or other property right claims or to contest validity of any such claims; this section has the sole purpose of protecting the integrity of the free software distribution system which is implemented by public license practices. Many people have made generous contributions to the wide range of software distributed through that system in reliance on consistent application of that system; it is up to the author/donor to decide if he or she is willing to distribute software through any other system and a licensee cannot impose that choice. This section is intended to make thoroughly clear what is believed to be a consequence of the rest of this License. 12. If the distribution and/or use of the Library is restricted in certain countries either by patents or by copyrighted interfaces, the original copyright holder who places the Library under this License may add an explicit geographical distribution limitation excluding those countries, so that distribution is permitted only in or among countries not thus excluded. In such case, this License incorporates the limitation as if written in the body of this License. 13. The Free Software Foundation may publish revised and/or new versions of the Lesser General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Library specifies a version number of this License which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Library does not specify a license version number, you may choose any version ever published by the Free Software Foundation. 14. If you wish to incorporate parts of the Library into other free programs whose distribution conditions are incompatible with these, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Libraries If you develop a new library, and you want it to be of the greatest possible use to the public, we recommend making it free software that everyone can redistribute and change. You can do so by permitting redistribution under these terms (or, alternatively, under the terms of the ordinary General Public License). To apply these terms, attach the following notices to the library. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA Also add information on how to contact you by electronic and paper mail. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the library, if necessary. Here is a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the library `Frob' (a library for tweaking knobs) written by James Random Hacker. , 1 April 1990 Ty Coon, President of Vice That's all there is to it! pam_p11-pam_p11-0.3.1/Makefile.am000066400000000000000000000013451353625622400162540ustar00rootroot00000000000000 AUTOMAKE_OPTIONS = foreign 1.10 ACLOCAL_AMFLAGS = -I m4 MAINTAINERCLEANFILES = \ config.log config.status \ $(srcdir)/Makefile.in \ $(srcdir)/config.h.in $(srcdir)/config.h.in~ $(srcdir)/configure \ $(srcdir)/install-sh $(srcdir)/ltmain.sh $(srcdir)/missing \ $(srcdir)/depcomp $(srcdir)/aclocal.m4 \ $(srcdir)/config.guess $(srcdir)/config.sub \ $(srcdir)/m4/ltsugar.m4 $(srcdir)/m4/libtool.m4 \ $(srcdir)/m4/ltversion.m4 $(srcdir)/m4/lt~obsolete.m4 \ $(srcdir)/m4/ltoptions.m4 \ $(srcdir)/packaged EXTRA_DIST = ./config.rpath .gitignore SUBDIRS = po src dist_noinst_SCRIPTS = bootstrap dist_doc_DATA = NEWS README.md # Allow detection of packaged tarball dist-hook: $(MKDIR_P) "$(distdir)/m4" echo > "$(distdir)/packaged" pam_p11-pam_p11-0.3.1/NEWS000066400000000000000000000030431353625622400147140ustar00rootroot00000000000000NEWS for Pam_p11 -- History of user visible changes New in 0.3.1; 2019-09-11; Frank Morgner * CVE-2019-16058: Fixed buffer overflow when creating signatures longer than 256 bytes New in 0.3.0; 2019-04-24; Frank Morgner * Add Italian translation * Add support for matching the PIN-input with a regular expression * Add support for macOS * Add support for building with OpenSSL 1.1.1 * Add support for nistp256/384/521 keys in authorized_keys file New in 0.2.0; 2018-05-16; Frank Morgner * Add user documentation in Readme.md * Add support for PIN pad readers * Add support for changing/unblocking PIN (use with passwd) * Add support for localized user feedback * Add support for cards without certificates (e.g. OpenPGP card) * Add support for PKCS#11 modules with multiple slots * Add support for building with OpenSSL 1.1 * Merged opensc and openssh module into pam_p11.so * Fixed memory leaks, coverity issues, compiler warnings * Created `test-passwd` and `test-login` for testing standard use cases New in 0.1.6; 2017-03-06; Alon Bar-Lev * Build system rewritten (NOTICE: configure options was modified). New in 0.1.5; 2008-08-27; Andreas Jellinghaus * fix script for wiki to html export. New in 0.1.4; 2008-07-31; Andreas Jellinghaus * new version with a number of build fixes New in 0.1.3; 2007-07-11; Andreas Jellinghaus * update wiki export script (add images, fix links). * make some functions static. * rename variables to avoid names of glibc functions (e.g. random). * do not save the password (i.e. pin - shouldn't go anywhere except to the card). pam_p11-pam_p11-0.3.1/README.md000066400000000000000000000145331353625622400155020ustar00rootroot00000000000000# Welcome to pam_p11 Pam_p11 is a plugable authentication module (pam) package for using crpytographic tokens such as smart cards and usb crypto tokens for authentication. Pam_p11 uses [libp11](https://github.com/OpenSC/libp11/) to access any PKCS#11 module. It should be compatible with any implementation, but it is primarely developed using [OpenSC](https://github.com/OpenSC/OpenSC/). Pam_p11 implements two authentication methods: - verify a token using a known public key found in OpenSSH's `~/.ssh/authorized_keys`. - verify a token using a known certificate found in `~/.eid/authorized_certificates`. Pam_p11 is very simple, it has no config file, does not know about certificate chains, certificate authorities, revocation lists or OCSP. Perfect for the small installation with no frills. Pam_p11 was written by an international team and is licensed as Open Source software under the LGPL license. [![Build Status](https://travis-ci.org/OpenSC/pam_p11.svg?branch=master)](https://travis-ci.org/OpenSC/pam_p11) [![Coverity Scan Status](https://scan.coverity.com/projects/15452/badge.svg)](https://scan.coverity.com/projects/opensc-pam_p11) ## Installing pam_p11 Installation is quite easy: ``` wget https://github.com/OpenSC/pam_p11/releases/download/pam_p11-0.1.6/pam_p11-0.1.6.tar.gz tar xfvz pam_p11-0.1.6.tar.gz cd pam_p11-0.1.6 ./configure --prefix=/usr --libdir=/lib/ make make install ``` Pam_p11 depends on pkg-config, openssl, libp11 and pam. If you don't have pkg-config installed, please do so and try again. If pkg-config is not found, please change your PATH environment setting. If openssl is not installed, please do so. If openssl is not found, please change your PKG_CONFIG_PATH environment setting to include the directory with "openssl.pc" or "libp11.pc" file. Some linux distributions split openssl into a runtime package and a development package, you need to install both. Same might be true for pam and libp11. ## Using pam_p11 ### Login To use pam_p11 with some application like `sudo`, edit `/etc/pam.d/sudo` and add something like the following at the beginning of the file: ``` auth sufficient /usr/local/lib/security/pam_p11.so /usr/local/lib/opensc-pkcs11.so ``` Replace `/usr/local/lib/opensc-pkcs11.so` with your PKCS#11 implementation. Using an absolute path to `pam_p11.so` avoids the need to write to a system directory, which is especially useful for macOS with system integrity protection (SIP) enabled. An optional second argument to `pam_p11.so` may be used to check for a specific format when prompting for the token's password. On macOS this defaults to the regular expression `^[[:digit:]]*$` to avoid confusion with the user's password in the login screen. pam_p11 uses [POSIX-Extended Regular Expressions](https://man.openbsd.org/re_format.7) for matching. While testing it is best to keep a door open. Editing the configuration files from a different machine via SSH helps reverting a bad PAM login configuration. Replace `sufficient` with `required` and remove other unwanted PAM modules from the file only when you've successfully verified the configuration. To enable pam_p11 for all logins (graphical and terminal based), change the following configuration files as described above: | Operating System | PAM configuration file | | ---------------- | -------------------------- | | macOS | `/etc/pam.d/authorization` | | Debian | `/etc/pam.d/common-auth` | | Arch Linux | `/etc/pam.d/system-auth` | ### PIN change and unblock To allow changing and unblocking the PIN via pam_p11, add the following to your configuration: ``` password optional /usr/local/lib/security/pam_p11.so /usr/local/lib/opensc-pkcs11.so ``` An optional second argument to `pam_p11.so` may be used to check for a specific format when prompting for the token's password. On macOS this defaults to the regular expression `^[[:digit:]]*$` to avoid confusion with the user's password in the login screen. pam_p11 uses [POSIX-Extended Regular Expressions](https://man.openbsd.org/re_format.7) for matching. ### User configuration via `~/.eid/authorized_certificates` A user may create a `~/.eid/` directory and create a file `~/.eid/authorized_certificates` with authorized certificates. You can do that via ``` mkdir -p ~/.eid chmod 0755 ~/.eid pkcs11-tool --read-object --type cert --id 45 --module /usr/lib/opensc-pkcs11.so --output-file cert.cer openssl x509 -inform DER -in cert.cer -outform PEM >> ~/.eid/authorized_certificates chmod 0644 ~/.eid/authorized_certificates ``` This example uses the `pkcs11-tool` command from opensc to read a certificate (id `45`) from the smart card. Use `pkcs11-tool --list-objects --type cert --module /usr/lib/opensc-pkcs11.so` to view all certificates available on the card. It is very important that only the user of the file can write to it. You can have any number of certificates in that file. The certificates need to be in PEM format. DER format is not supported. ### User configuration via `~/.ssh/authorized_keys` A user may create a `~/.ssh/` directory and create a file `~/.ssh/authorized_keys` with authorized public keys. You can do that via ``` mkdir -p ~/.ssh chmod 0755 ~/.ssh ssh-keygen -D /usr/lib/opensc-pkcs11.so >> ~/.ssh/authorized_keys chmod 0644 ~/.ssh/authorized_keys ``` This example uses the `ssh-keygen` command from openssh to read the default user public key (id 45) from the smart card in reader 0. Note that this tool prints the public keys in two formats: ssh v1 and ssh v2 format. It is recommended to edit the file and delete one of those two lines. Also you might want to add a comment / identifier at the end of the line. It is very important that only the user of the file can write to it. You can have any number of public keys in that file. Note it is currently not possible to convert existing ssh keys into pem format and store them on a smart card. (To be precise: OpenSC has no such functionality, not sure about other implementations.) ## Security Note pam_p11 simply compares public keys and request the cryptographic token to sign some random data and verifiy the signature with the public key. No CA chain checking is done, no CRL is looked at, and they don't know what OCSP is. This works fine for small installations, but if you want any of those features, please have a look at [Pam_pkcs11](https://github.com/OpenSC/pam_pkcs11) for a fully fledged PAM module for smart card authentication. pam_p11-pam_p11-0.3.1/bootstrap000077500000000000000000000003131353625622400161550ustar00rootroot00000000000000#!/bin/sh set -e set -x if test -f Makefile; then make distclean fi rm -rf *~ *.cache *.m4 config.guess config.log \ config.status config.sub depcomp ltmain.sh autoreconf --verbose --install --force pam_p11-pam_p11-0.3.1/configure.ac000066400000000000000000000072771353625622400165200ustar00rootroot00000000000000AC_PREREQ(2.60) define([PACKAGE_VERSION_MAJOR], [0]) define([PACKAGE_VERSION_MINOR], [3]) define([PACKAGE_VERSION_FIX], [1]) define([PACKAGE_SUFFIX], []) define([PRODUCT_BUGREPORT], [https://github.com/OpenSC/pam_p11/issues]) AC_INIT([pam_p11],[PACKAGE_VERSION_MAJOR.PACKAGE_VERSION_MINOR.PACKAGE_VERSION_FIX[]PACKAGE_SUFFIX],[PRODUCT_BUGREPORT]) AC_CONFIG_AUX_DIR([.]) AM_CONFIG_HEADER([config.h]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE AC_CONFIG_SRCDIR([src/pam_p11.c]) AC_CANONICAL_HOST AC_PROG_CC PKG_PROG_PKG_CONFIG AC_C_BIGENDIAN AC_ARG_ENABLE( [strict], [AS_HELP_STRING([--disable-strict],[disable strict compile mode @<:@enabled@:>@])], , [enable_strict="yes"] ) AC_ARG_ENABLE( [pedantic], [AS_HELP_STRING([--enable-pedantic],[enable pedantic compile mode @<:@disabled@:>@])], , [enable_pedantic="no"] ) AC_ARG_WITH( [pamdir], [AS_HELP_STRING([--with-pamdir=PATH],[Specify the directory where PAM modules are stored])], [pamdir="${withval}"], [ if test "${prefix}" = "/usr"; then pamdir="/lib${libdir##*/lib}/security" else pamdir="\$(libdir)/security" fi ] ) AM_GNU_GETTEXT([external]) AM_GNU_GETTEXT_VERSION(0.18.3) dnl Add the languages which your application supports here. ALL_LINGUAS="de it" dnl Checks for programs. AC_PROG_CPP AC_PROG_INSTALL AC_PROG_LN_S AC_PROG_MKDIR_P AC_PROG_SED AC_PROG_MAKE_SET dnl Add libtool support. ifdef( [LT_INIT], [LT_INIT], [AC_PROG_LIBTOOL] ) PKG_CHECK_MODULES([LIBP11], [libp11 >= 0.2.4],, [AC_MSG_ERROR([libp11 is required])]) PKG_CHECK_MODULES( [OPENSSL], [libcrypto >= 0.9.7], , [PKG_CHECK_MODULES( [OPENSSL], [openssl >= 0.9.7], , [AC_CHECK_LIB( [crypto], [RSA_version], [OPENSSL_LIBS="-lcrypto"], [AC_MSG_ERROR([Cannot find OpenSSL])] )] )] ) saved_LIBS="$LIBS" LIBS="$OPENSSL_LIBS $LIBS" AC_CHECK_FUNCS(EVP_MD_CTX_new EVP_MD_CTX_free EVP_MD_CTX_reset) LIBS="$saved_LIBS" if test -z "${PAM_LIBS}"; then AC_ARG_VAR([PAM_CFLAGS], [C compiler flags for pam]) AC_ARG_VAR([PAM_LIBS], [linker flags for pam]) AC_CHECK_LIB( [pam], [pam_authenticate], [PAM_LIBS="-lpam"], [AC_MSG_ERROR([Cannot find pam])] ) fi saved_CFLAGS="${CFLAGS}" CFLAGS="${CFLAGS} ${OPENSSL_CFLAGS} ${LIBP11_CFLAGS} ${PAM_CFLAGS}" LIBS="$LIBS ${OPENSSL_LIBS} ${LIBP11_LIBS} ${PAM_LIBS}" dnl Checks for header files. AC_HEADER_STDC AC_HEADER_SYS_WAIT AC_CHECK_HEADERS([ \ string.h syslog.h fcntl.h unistd.h security/pam_ext.h security/pam_misc.h \ ]) AC_TYPE_SIZE_T AC_FUNC_MALLOC AC_FUNC_REALLOC AC_FUNC_STAT AC_FUNC_VPRINTF AC_CHECK_FUNCS([memset strdup strerror PKCS11_enumerate_public_keys PKCS11_is_logged_in pam_vprompt openpam_ttyconv]) AC_CHECK_LIB([pam_misc], [misc_conv]) AM_CONDITIONAL([HAVE_PAM_MISC], [test "$ac_cv_lib_pam_misc_misc_conv" = yes]) CFLAGS="${saved_CFLAGS}" LIBS="$saved_LIBS" AC_SUBST([pamdir]) if test "${enable_pedantic}" = "yes"; then enable_strict="yes"; CFLAGS="${CFLAGS} -pedantic" fi if test "${enable_strict}" = "yes"; then CFLAGS="${CFLAGS} -Wall -Wextra -Wno-unused-parameter -Werror" fi AC_CONFIG_FILES([ Makefile src/Makefile po/Makefile.in ]) AC_OUTPUT cat <, 2018. # msgid "" msgstr "" "Project-Id-Version: pam_p11 0.1.7_git\n" "Report-Msgid-Bugs-To: https://github.com/OpenSC/pam_p11/issues\n" "POT-Creation-Date: 2019-09-11 22:42+0200\n" "PO-Revision-Date: 2018-04-05 11:14+0200\n" "Last-Translator: Frank Morgner \n" "Language-Team: German\n" "Language: de\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" #: src/pam_p11.c:205 msgid "Error loading PKCS#11 module" msgstr "Fehler beim Laden des PKCS#11-Moduls" #: src/pam_p11.c:213 src/pam_p11.c:265 msgid "Error initializing PKCS#11 module" msgstr "Fehler beim Initialisieren des PKCS#11-Moduls" #: src/pam_p11.c:333 msgid " (last try)" msgstr " (letzter Versuch)" #: src/pam_p11.c:340 #, c-format msgid "Login on PIN pad with %s%s" msgstr "Login auf dem PIN-Pad mit %s%s" #: src/pam_p11.c:346 #, c-format msgid "Login with %s%s: " msgstr "Login mit %s%s: " #: src/pam_p11.c:370 msgid "Invalid PIN" msgstr "" #: src/pam_p11.c:378 msgid "PIN not verified; PIN locked" msgstr "PIN nicht verifiziert; PIN gesperrt" #: src/pam_p11.c:380 msgid "PIN not verified; one try remaining" msgstr "PIN nicht verifiziert; ein Versuch verbleibend" #: src/pam_p11.c:382 msgid "PIN not verified" msgstr "PIN nicht verifiziert" #: src/pam_p11.c:424 #, c-format msgid "Change PIN with PUK on PIN pad for %s" msgstr "Ändere PIN mit PUK auf dem PIN-Pad für %s" #: src/pam_p11.c:428 #, c-format msgid "Change PIN on PIN pad for %s" msgstr "Ändere PIN auf dem PIN-Pad für %s" #: src/pam_p11.c:435 #, c-format msgid "PUK for %s: " msgstr "PUK für %s: " #: src/pam_p11.c:446 msgid "Current PIN: " msgstr "Aktuelle PIN: " #: src/pam_p11.c:464 msgid "Enter new PIN: " msgstr "Neue PIN eingeben: " #: src/pam_p11.c:467 msgid "Retype new PIN: " msgstr "Neue PIN wiederholen: " #: src/pam_p11.c:471 msgid "PINs don't match" msgstr "PINs verschieden" #: src/pam_p11.c:478 #, fuzzy msgid "PIN not changed; PIN locked" msgstr "PIN nicht verifiziert; PIN gesperrt" #: src/pam_p11.c:480 #, fuzzy msgid "PIN not changed; one try remaining" msgstr "PIN nicht verifiziert; ein Versuch verbleibend" #: src/pam_p11.c:482 #, fuzzy msgid "PIN not changed" msgstr "PIN nicht verifiziert" #: src/pam_p11.c:610 msgid "No token found" msgstr "Kein Token gefunden" #: src/pam_p11.c:612 msgid "No authorized keys on token" msgstr "Keine autorisierten Schlüssel auf dem Token" #: src/pam_p11.c:674 msgid "Error verifying key" msgstr "Fehler beim Verifizieren des Schlüssels" pam_p11-pam_p11-0.3.1/po/it.po000066400000000000000000000052221353625622400156100ustar00rootroot00000000000000# Italian translation for pam-p11 # Copyright (c) 2019 OpenSC Project # This file is distributed under the same license as the pam-p11 package. # Milo Casagrande , 2019. # msgid "" msgstr "" "Project-Id-Version: pam-p11\n" "Report-Msgid-Bugs-To: https://github.com/OpenSC/pam_p11/issues\n" "POT-Creation-Date: 2019-09-11 22:42+0200\n" "PO-Revision-Date: 2019-02-28 14:03+0000\n" "Last-Translator: Milo Casagrande \n" "Language-Team: Italian \n" "Language: it\n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" #: src/pam_p11.c:205 msgid "Error loading PKCS#11 module" msgstr "Errore nel caricare il modulo PKCS#11" #: src/pam_p11.c:213 src/pam_p11.c:265 msgid "Error initializing PKCS#11 module" msgstr "Errore nell'inizializzare il modulo PKCS#11" #: src/pam_p11.c:333 msgid " (last try)" msgstr " (ultimo tentativo)" #: src/pam_p11.c:340 #, c-format msgid "Login on PIN pad with %s%s" msgstr "Accesso su dispositivo inserimento PIN con %s%s" #: src/pam_p11.c:346 #, c-format msgid "Login with %s%s: " msgstr "Accesso con %s%s: " #: src/pam_p11.c:370 msgid "Invalid PIN" msgstr "" #: src/pam_p11.c:378 msgid "PIN not verified; PIN locked" msgstr "PIN non verificato; PIN bloccato" #: src/pam_p11.c:380 msgid "PIN not verified; one try remaining" msgstr "PIN non verificato; un tentativo rimasto" #: src/pam_p11.c:382 msgid "PIN not verified" msgstr "PIN non verificato" #: src/pam_p11.c:424 #, c-format msgid "Change PIN with PUK on PIN pad for %s" msgstr "Modifica del PIN con PUK su dispositivo inserimento PIN per %s" #: src/pam_p11.c:428 #, c-format msgid "Change PIN on PIN pad for %s" msgstr "Modifica del PIN su dispositivo inserimento PIN per %s" #: src/pam_p11.c:435 #, c-format msgid "PUK for %s: " msgstr "PUK per %s: " #: src/pam_p11.c:446 msgid "Current PIN: " msgstr "PIN attuale: " #: src/pam_p11.c:464 msgid "Enter new PIN: " msgstr "Inserire nuovo PIN: " #: src/pam_p11.c:467 msgid "Retype new PIN: " msgstr "Ripetere nuovo PIN: " #: src/pam_p11.c:471 msgid "PINs don't match" msgstr "I PIN non sono uguali" #: src/pam_p11.c:478 msgid "PIN not changed; PIN locked" msgstr "PIN non modificato; PIN bloccato" #: src/pam_p11.c:480 msgid "PIN not changed; one try remaining" msgstr "PIN non modificato; un tentativo rimasto" #: src/pam_p11.c:482 msgid "PIN not changed" msgstr "PIN non modificato" #: src/pam_p11.c:610 msgid "No token found" msgstr "Nessun token trovato" #: src/pam_p11.c:612 msgid "No authorized keys on token" msgstr "Nessuna chiave autorizzata sul token" #: src/pam_p11.c:674 msgid "Error verifying key" msgstr "Errore nel verificare la chiave" pam_p11-pam_p11-0.3.1/po/pam_p11.pot000066400000000000000000000040161353625622400166160ustar00rootroot00000000000000# SOME DESCRIPTIVE TITLE. # Copyright (C) YEAR OpenSC Project # This file is distributed under the same license as the pam_p11 package. # FIRST AUTHOR , YEAR. # #, fuzzy msgid "" msgstr "" "Project-Id-Version: pam_p11 0.3.1\n" "Report-Msgid-Bugs-To: https://github.com/OpenSC/pam_p11/issues\n" "POT-Creation-Date: 2019-09-11 22:42+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" "Language: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" #: src/pam_p11.c:205 msgid "Error loading PKCS#11 module" msgstr "" #: src/pam_p11.c:213 src/pam_p11.c:265 msgid "Error initializing PKCS#11 module" msgstr "" #: src/pam_p11.c:333 msgid " (last try)" msgstr "" #: src/pam_p11.c:340 #, c-format msgid "Login on PIN pad with %s%s" msgstr "" #: src/pam_p11.c:346 #, c-format msgid "Login with %s%s: " msgstr "" #: src/pam_p11.c:370 msgid "Invalid PIN" msgstr "" #: src/pam_p11.c:378 msgid "PIN not verified; PIN locked" msgstr "" #: src/pam_p11.c:380 msgid "PIN not verified; one try remaining" msgstr "" #: src/pam_p11.c:382 msgid "PIN not verified" msgstr "" #: src/pam_p11.c:424 #, c-format msgid "Change PIN with PUK on PIN pad for %s" msgstr "" #: src/pam_p11.c:428 #, c-format msgid "Change PIN on PIN pad for %s" msgstr "" #: src/pam_p11.c:435 #, c-format msgid "PUK for %s: " msgstr "" #: src/pam_p11.c:446 msgid "Current PIN: " msgstr "" #: src/pam_p11.c:464 msgid "Enter new PIN: " msgstr "" #: src/pam_p11.c:467 msgid "Retype new PIN: " msgstr "" #: src/pam_p11.c:471 msgid "PINs don't match" msgstr "" #: src/pam_p11.c:478 msgid "PIN not changed; PIN locked" msgstr "" #: src/pam_p11.c:480 msgid "PIN not changed; one try remaining" msgstr "" #: src/pam_p11.c:482 msgid "PIN not changed" msgstr "" #: src/pam_p11.c:610 msgid "No token found" msgstr "" #: src/pam_p11.c:612 msgid "No authorized keys on token" msgstr "" #: src/pam_p11.c:674 msgid "Error verifying key" msgstr "" pam_p11-pam_p11-0.3.1/src/000077500000000000000000000000001353625622400150045ustar00rootroot00000000000000pam_p11-pam_p11-0.3.1/src/Makefile.am000066400000000000000000000015271353625622400170450ustar00rootroot00000000000000MAINTAINERCLEANFILES = $(srcdir)/Makefile.in AM_CFLAGS = $(OPENSSL_CFLAGS) $(LIBP11_CFLAGS) $(PAM_CFLAGS) -DLOCALEDIR=\"$(localedir)\" LIBS = $(OPENSSL_LIBS) $(LIBP11_LIBS) $(PAM_LIBS) AM_LDFLAGS = -module -avoid-version -shared -no-undefined \ -export-symbols "$(srcdir)/pam_p11.exports" pam_LTLIBRARIES = pam_p11.la pam_p11_la_SOURCES = pam_p11.c base64.c \ match_openssh.c match_opensc.c \ pam_p11.exports noinst_PROGRAMS = test-login test-passwd test_login_SOURCES = test.c login.c $(pam_p11_la_SOURCES) test_login_CFLAGS = $(AM_CFLAGS) -DLIBDIR=\"$(libdir)\" -DTEST test_passwd_SOURCES = test.c passwd.c $(pam_p11_la_SOURCES) test_passwd_CFLAGS = $(AM_CFLAGS) -DLIBDIR=\"$(libdir)\" -DTEST if HAVE_PAM_MISC test_login_LDADD = -lpam_misc test_passwd_LDADD = -lpam_misc endif format: indent -kr -i8 -ts8 -sob -l80 -ss -ncs *.c *.h pam_p11-pam_p11-0.3.1/src/base64.c000066400000000000000000000053071353625622400162410ustar00rootroot00000000000000/* * base64.c: Base64 converting functions * * Copyright (C) 2001, 2002 Juha Yrjölä * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include extern int sc_base64_decode(const char *in, unsigned char *out, size_t outlen); static const unsigned char bin_table[128] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xD0, 0xFF, 0xFF, 0xD0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xF2, 0xFF, 0x3F, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0xC0, 0xFF, 0xFF, 0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, }; static int from_base64(const char *in, unsigned int *out, int *skip) { unsigned int res = 0, c, s = 18; const char *in0 = in; for (c = 0; c < 4; c++, in++) { unsigned char b; int k = *in; if (k < 0 || k >= (int)sizeof(bin_table)) return -1; if (k == 0 && c == 0) return 0; b = bin_table[k]; if (b == 0xC0) /* '=' */ break; switch (b) { case 0xD0: /* '\n' or '\r' */ c--; continue; } if (b > 0x3f) return -1; res |= b << s; s -= 6; } *skip = in - in0; *out = res; return c * 6 / 8; } int sc_base64_decode(const char *in, unsigned char *out, size_t outlen) { int len = 0, r, skip; unsigned int i; while ((r = from_base64(in, &i, &skip)) > 0) { int finished = 0, s = 16; if (r < 3) finished = 1; while (r--) { if (outlen <= 0) return -1; *out++ = i >> s; s -= 8; outlen--; len++; } in += skip; if (finished || *in == 0) return len; } if (r == 0) return len; return -1; } pam_p11-pam_p11-0.3.1/src/login.c000066400000000000000000000023451353625622400162640ustar00rootroot00000000000000/* * Copyright (C) 2018 Frank Morgner * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include extern int pam_sm_test(pam_handle_t *pamh, int flags, int argc, const char **argv); int pam_sm_test(pam_handle_t *pamh, int flags, int argc, const char **argv) { int r; r = pam_sm_authenticate(pamh, flags, argc, argv); if (PAM_SUCCESS != r) goto err; r = pam_sm_acct_mgmt(pamh, flags, argc, argv); if (PAM_SUCCESS != r) goto err; err: return r; } pam_p11-pam_p11-0.3.1/src/match_opensc.c000066400000000000000000000021571353625622400176200ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include #include extern int match_user_opensc(EVP_PKEY *authkey, const char *login) { char filename[PATH_MAX]; struct passwd *pw; int found; BIO *in; X509 *cert = NULL; if (NULL == authkey || NULL == login) return -1; pw = getpwnam(login); if (!pw || !pw->pw_dir) return -1; snprintf(filename, PATH_MAX, "%s/.eid/authorized_certificates", pw->pw_dir); in = BIO_new(BIO_s_file()); if (!in) return -1; if (BIO_read_filename(in, filename) != 1) { syslog(LOG_ERR, "BIO_read_filename from %s failed\n", filename); return -1; } found = 0; do { EVP_PKEY *key; if (NULL == PEM_read_bio_X509(in, &cert, 0, NULL)) { break; } key = X509_get_pubkey(cert); if (key == NULL) continue; if (1 == EVP_PKEY_cmp(authkey, key)) { found = 1; } EVP_PKEY_free(key); } while (found == 0); if (cert) { X509_free(cert); } BIO_free(in); return found; } pam_p11-pam_p11-0.3.1/src/match_openssh.c000066400000000000000000000201451353625622400200050ustar00rootroot00000000000000#include #include #include #include #include #include #include #include #include #include #include /* how to read the authorized_keys file and the key? * see openssh source code auth2-pubkey.c user_key_allowed2 * and misc.c read_keyfile_line and key.c */ #define OPENSSH_LINE_MAX 16384 /* from openssh SSH_MAX_PUBKEY_BYTES */ #if (OPENSSL_VERSION_NUMBER < 0x10100000L) || defined (LIBRESSL_VERSION_NUMBER) void RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) { if (n != NULL) *n = r->n; if (e != NULL) *e = r->e; if (d != NULL) *d = r->d; } int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) { /* If the fields n and e in r are NULL, the corresponding input * parameters MUST be non-NULL for n and e. d may be * left NULL (in case only the public key is used). */ if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) return 0; if (n != NULL) { BN_free(r->n); r->n = n; } if (e != NULL) { BN_free(r->e); r->e = e; } if (d != NULL) { BN_free(r->d); r->d = d; } return 1; } #endif static EVP_PKEY *ssh1_line_to_key(char *line) { EVP_PKEY *key; RSA *rsa; char *b, *e, *m, *c; BIGNUM *rsa_e, *rsa_n; key = EVP_PKEY_new(); if (!key) return NULL; rsa = RSA_new(); if (!rsa) goto err; /* first digitstring: the bits */ b = line; /* second digitstring: the exponent */ /* skip all digits */ for (e = b; *e >= '0' && *e <= '0'; e++) ; /* must be a whitespace */ if (*e != ' ' && *e != '\t') return NULL; /* cut the string in two part */ *e = 0; e++; /* skip more whitespace */ while (*e == ' ' || *e == '\t') e++; /* third digitstring: the modulus */ /* skip all digits */ for (m = e; *m >= '0' && *m <= '0'; m++) ; /* must be a whitespace */ if (*m != ' ' && *m != '\t') return NULL; /* cut the string in two part */ *m = 0; m++; /* skip more whitespace */ while (*m == ' ' || *m == '\t') m++; /* look for a comment after the modulus */ for (c = m; *c >= '0' && *c <= '0'; c++) ; /* could be a whitespace or end of line */ if (*c != ' ' && *c != '\t' && *c != '\n' && *c != '\r' && *c != 0) return NULL; if (*c == ' ' || *c == '\t') { *c = 0; c++; /* skip more whitespace */ while (*c == ' ' || *c == '\t') c++; if (*c && *c != '\r' && *c != '\n') { /* we have a comment */ } else { c = NULL; } } else { *c = 0; c = NULL; } /* ok, now we have b e m pointing to pure digit * null terminated strings and maybe c pointing to a comment */ BN_dec2bn(&rsa_e, e); BN_dec2bn(&rsa_n, m); if (!RSA_set0_key(rsa, rsa_n, rsa_e, NULL)) goto err; EVP_PKEY_assign_RSA(key, rsa); return key; err: EVP_PKEY_free(key); return NULL; } extern int sc_base64_decode(const char *in, unsigned char *out, size_t outlen); static EVP_PKEY *ssh2_line_to_key(char *line) { EVP_PKEY *key; RSA *rsa; BIGNUM *rsa_e, *rsa_n; unsigned char decoded[OPENSSH_LINE_MAX]; int len; char *b, *c; int i; /* find the mime-blob */ b = line; if (!b) return NULL; /* find the first whitespace */ while (*b && *b != ' ') b++; /* skip that whitespace */ b++; /* find the end of the blob / comment */ for (c = b; *c && *c != ' ' && 'c' != '\t' && *c != '\r' && *c != '\n'; c++) ; *c = 0; /* decode binary data */ if (sc_base64_decode(b, decoded, OPENSSH_LINE_MAX) < 0) return NULL; i = 0; /* get integer from blob */ len = (decoded[i] << 24) + (decoded[i + 1] << 16) + (decoded[i + 2] << 8) + (decoded[i + 3]); i += 4; /* now: key_from_blob */ if (strncmp((char *)&decoded[i], "ssh-rsa", 7) != 0) return NULL; i += len; /* to prevent access beyond 'decoded' array, index 'i' must be always checked */ if ( i + 4 > OPENSSH_LINE_MAX ) return NULL; /* get integer from blob */ len = (decoded[i] << 24) + (decoded[i + 1] << 16) + (decoded[i + 2] << 8) + (decoded[i + 3]); i += 4; if ( i + len > OPENSSH_LINE_MAX ) return NULL; /* get bignum */ rsa_e = BN_bin2bn(decoded + i, len, NULL); i += len; if ( i + 4 > OPENSSH_LINE_MAX ) return NULL; /* get integer from blob */ len = (decoded[i] << 24) + (decoded[i + 1] << 16) + (decoded[i + 2] << 8) + (decoded[i + 3]); i += 4; if ( i + len > OPENSSH_LINE_MAX ) return NULL; /* get bignum */ rsa_n = BN_bin2bn(decoded + i, len, NULL); key = EVP_PKEY_new(); rsa = RSA_new(); /* set e and n */ if (!RSA_set0_key(rsa, rsa_n, rsa_e, NULL)) { EVP_PKEY_free(key); RSA_free(rsa); return NULL; } EVP_PKEY_assign_RSA(key, rsa); return key; } static EVP_PKEY *ssh_nistp_line_to_key(char *line) { EVP_PKEY *key; EC_KEY *ec_key; BIGNUM *x; BIGNUM *y; unsigned char decoded[OPENSSH_LINE_MAX]; int len; int flen; char *b, *c; int i; int nid; /* check allowed key size */ if (strncmp(line + 16, "256", 3) == 0) flen = 32, nid = NID_X9_62_prime256v1; else if (strncmp(line + 16, "384", 3) == 0) flen = 48, nid = NID_secp384r1; else if (strncmp(line + 16, "521", 3) == 0) flen = 66, nid = NID_secp521r1; else return NULL; /* find the mime-blob */ b = line; if (!b) return NULL; /* find the first whitespace */ while (*b && *b != ' ') b++; /* skip that whitespace */ b++; /* find the end of the blob / comment */ for (c = b; *c && *c != ' ' && 'c' != '\t' && *c != '\r' && *c != '\n'; c++) ; *c = 0; /* decode binary data */ if (sc_base64_decode(b, decoded, OPENSSH_LINE_MAX) < 0) return NULL; i = 0; /* get integer from blob */ len = (decoded[i] << 24) + (decoded[i + 1] << 16) + (decoded[i + 2] << 8) + (decoded[i + 3]); i += 4; /* always check 'len' to get safe 'i' as index into 'decoded' array */ if (len != 19) return NULL; /* check key type (must be same in decoded data and at line start) */ if (strncmp((char *)&decoded[i], line, 19) != 0) return NULL; i += len; /* get integer from blob */ len = (decoded[i] << 24) + (decoded[i + 1] << 16) + (decoded[i + 2] << 8) + (decoded[i + 3]); i += 4; /* check curve name - must match key type */ if(len != 8) return NULL; if (strncmp((char *)&decoded[i], line + 11, 8) != 0) return NULL; i += len; /* get integer from blob */ len = (decoded[i] << 24) + (decoded[i + 1] << 16) + (decoded[i + 2] << 8) + (decoded[i + 3]); i += 4; /* read public key (uncompressed point) */ /* test if data length is corresponding to key size */ if (len != 1 + flen * 2) return NULL; /* check uncompressed indicator */ if (decoded[i] != 4 ) return NULL; i++; /* create key */ ec_key = EC_KEY_new_by_curve_name(nid); /* read point coordinates */ x = BN_bin2bn(decoded + i, flen, NULL); i += flen; y = BN_bin2bn(decoded + i, flen, NULL); /* do error checking here: valid x, y, ec_key, point on curve.. */ if (!EC_KEY_set_public_key_affine_coordinates(ec_key, x, y)) { EC_KEY_free(ec_key); BN_free(x); BN_free(y); return NULL; } key = EVP_PKEY_new(); EVP_PKEY_assign_EC_KEY(key, ec_key); return key; } extern int match_user_openssh(EVP_PKEY *authkey, const char *login) { char filename[PATH_MAX]; char line[OPENSSH_LINE_MAX]; struct passwd *pw; int found; FILE *file; pw = getpwnam(login); if (!pw || !pw->pw_dir) return -1; snprintf(filename, PATH_MAX, "%s/.ssh/authorized_keys", pw->pw_dir); file = fopen(filename, "r"); if (!file) return -1; found = 0; do { EVP_PKEY *key = NULL; char *cp; if (!fgets(line, sizeof line, file)) break; /* Skip leading whitespace, empty and comment lines. */ for (cp = line; *cp == ' ' || *cp == '\t'; cp++) { } if (!*cp || *cp == '\n' || *cp == '#') { continue; } if (*cp >= '0' && *cp <= '9') { /* ssh v1 key format */ key = ssh1_line_to_key(cp); } else if (strncmp("ssh-rsa", cp, 7) == 0) { /* ssh v2 rsa key format */ key = ssh2_line_to_key(cp); } else if (strncmp("ecdsa-sha2-nistp", cp, 16) == 0) { /* ssh nistp256/384/521 key */ key = ssh_nistp_line_to_key(cp); } if (key == NULL) continue; if (1 == EVP_PKEY_cmp(authkey, key)) { found = 1; } EVP_PKEY_free(key); } while (found == 0); fclose(file); return found; } pam_p11-pam_p11-0.3.1/src/pam_p11.c000066400000000000000000000505751353625622400164220ustar00rootroot00000000000000/* * libp11 PAM Login Module * Copyright (C) 2003 Mario Strasser , * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #ifndef PACKAGE #define PACKAGE "pam_p11" #endif #include #include #include #include #include #include #include #include #include #include #include #include /* openssl deprecated API emulation */ #ifndef HAVE_EVP_MD_CTX_NEW #define EVP_MD_CTX_new() EVP_MD_CTX_create() #endif #ifndef HAVE_EVP_MD_CTX_FREE #define EVP_MD_CTX_free(ctx) EVP_MD_CTX_destroy((ctx)) #endif #ifndef HAVE_EVP_MD_CTX_RESET #define EVP_MD_CTX_reset(ctx) EVP_MD_CTX_cleanup((ctx)) #endif #ifdef ENABLE_NLS #include #include #define _(string) gettext(string) #ifndef LOCALEDIR #define LOCALEDIR "/usr/share/locale" #endif #else #define _(string) string #endif /* We have to make this definitions before we include the pam header files! */ #define PAM_SM_AUTH #define PAM_SM_ACCOUNT #define PAM_SM_SESSION #define PAM_SM_PASSWORD #include #include #ifdef HAVE_SECURITY_PAM_EXT_H #include #else #define pam_syslog(handle, level, msg...) syslog(level, ## msg) #endif #ifndef HAVE_PAM_VPROMPT static int pam_vprompt(pam_handle_t *pamh, int style, char **response, const char *fmt, va_list args) { int r = PAM_CRED_INSUFFICIENT; const struct pam_conv *conv; struct pam_message msg; struct pam_response *resp = NULL; struct pam_message *(msgp[1]); char text[128]; vsnprintf(text, sizeof text, fmt, args); msgp[0] = &msg; msg.msg_style = style; msg.msg = text; if (PAM_SUCCESS != pam_get_item(pamh, PAM_CONV, (const void **) &conv) || NULL == conv || NULL == conv->conv || conv->conv(1, (const struct pam_message **) msgp, &resp, conv->appdata_ptr) || NULL == resp) { goto err; } if (NULL != response) { if (resp[0].resp) { *response = strdup(resp[0].resp); if (NULL == *response) { pam_syslog(pamh, LOG_CRIT, "strdup() failed: %s", strerror(errno)); goto err; } } else { *response = NULL; } } r = PAM_SUCCESS; err: if (resp) { OPENSSL_cleanse(&resp[0].resp, sizeof resp[0].resp); free(&resp[0]); } return r; } #endif #ifndef PAM_EXTERN #define PAM_EXTERN extern #endif int prompt(int flags, pam_handle_t *pamh, int style, char **response, const char *fmt, ...) { int r; if (PAM_SILENT == (flags & PAM_SILENT) && style != PAM_TEXT_INFO && style != PAM_PROMPT_ECHO_OFF) { /* PAM_SILENT does not override the prompting of the user for passwords * etc., it only stops informative messages from being generated. We * use PAM_TEXT_INFO and PAM_PROMPT_ECHO_OFF exclusively for the * password prompt. */ r = PAM_SUCCESS; } else { va_list args; va_start (args, fmt); if (!response) { char *p = NULL; r = pam_vprompt(pamh, style, &p, fmt, args); free(p); } else { r = pam_vprompt(pamh, style, response, fmt, args); } va_end(args); } return r; } struct module_data { PKCS11_CTX *ctx; PKCS11_SLOT *slots; unsigned int nslots; int module_loaded; }; #ifdef TEST static struct module_data *global_module_data = NULL; #endif void module_data_cleanup(pam_handle_t *pamh, void *data, int error_status) { struct module_data *module_data = data; if (module_data) { if (1 == module_data->module_loaded) { PKCS11_release_all_slots(module_data->ctx, module_data->slots, module_data->nslots); PKCS11_CTX_unload(module_data->ctx); } PKCS11_CTX_free(module_data->ctx); EVP_cleanup(); ERR_free_strings(); free(module_data); } } static int module_initialize(pam_handle_t * pamh, int flags, int argc, const char **argv, struct module_data **module_data) { int r; struct module_data *data = calloc(1, sizeof *data); if (NULL == data) { pam_syslog(pamh, LOG_CRIT, "calloc() failed: %s", strerror(errno)); r = PAM_BUF_ERR; goto err; } #ifdef ENABLE_NLS setlocale(LC_ALL, ""); bindtextdomain(PACKAGE, LOCALEDIR); textdomain(PACKAGE); #endif /* Initialize OpenSSL */ OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Load and initialize PKCS#11 module */ data->ctx = PKCS11_CTX_new(); if (0 == argc || NULL == data->ctx || 0 != PKCS11_CTX_load(data->ctx, argv[0])) { pam_syslog(pamh, LOG_ALERT, "Loading PKCS#11 engine failed: %s\n", ERR_reason_error_string(ERR_get_error())); prompt(flags, pamh, PAM_ERROR_MSG , NULL, _("Error loading PKCS#11 module")); r = PAM_NO_MODULE_DATA; goto err; } data->module_loaded = 1; if (0 != PKCS11_enumerate_slots(data->ctx, &data->slots, &data->nslots)) { pam_syslog(pamh, LOG_ALERT, "Initializing PKCS#11 engine failed: %s\n", ERR_reason_error_string(ERR_get_error())); prompt(flags, pamh, PAM_ERROR_MSG , NULL, _("Error initializing PKCS#11 module")); r = PAM_AUTHINFO_UNAVAIL; goto err; } #ifdef TEST /* pam_set_data() is reserved for actual modules. For testing this would * return PAM_SYSTEM_ERR, so we're saving the module data in a static * variable. */ r = PAM_SUCCESS; global_module_data = data; #else r = pam_set_data(pamh, PACKAGE, data, module_data_cleanup); if (PAM_SUCCESS != r) { goto err; } #endif *module_data = data; data = NULL; err: module_data_cleanup(pamh, data, r); return r; } static int module_refresh(pam_handle_t *pamh, int flags, int argc, const char **argv, const char **user, PKCS11_CTX **ctx, PKCS11_SLOT **slots, unsigned int *nslots, const char **pin_regex) { int r; struct module_data *module_data; if (PAM_SUCCESS != pam_get_data(pamh, PACKAGE, (void *)&module_data) || NULL == module_data) { r = module_initialize(pamh, flags, argc, argv, &module_data); if (PAM_SUCCESS != r) { goto err; } } else { /* refresh all known slots */ PKCS11_release_all_slots(module_data->ctx, module_data->slots, module_data->nslots); module_data->slots = NULL; module_data->nslots = 0; if (0 != PKCS11_enumerate_slots(module_data->ctx, &module_data->slots, &module_data->nslots)) { pam_syslog(pamh, LOG_ALERT, "Initializing PKCS#11 engine failed: %s\n", ERR_reason_error_string(ERR_get_error())); prompt(flags, pamh, PAM_ERROR_MSG , NULL, _("Error initializing PKCS#11 module")); r = PAM_AUTHINFO_UNAVAIL; goto err; } } if (1 < argc) { *pin_regex = argv[1]; } else { #ifdef __APPLE__ /* If multiple PAMs are allowed for macOS' login, then the captured * password is used for all possible modules. To not block the token's * PIN if the user enters his standard password, we're refusing to use * anything that doesn't look like a PIN. */ *pin_regex = "^[[:digit:]]*$"; #else *pin_regex = NULL; #endif } r = pam_get_user(pamh, user, NULL); if (PAM_SUCCESS != r) { pam_syslog(pamh, LOG_ERR, "pam_get_user() failed %s", pam_strerror(pamh, r)); r = PAM_USER_UNKNOWN; goto err; } *ctx = module_data->ctx; *nslots = module_data->nslots; *slots = module_data->slots; err: return r; } extern int match_user_opensc(EVP_PKEY *authkey, const char *login); extern int match_user_openssh(EVP_PKEY *authkey, const char *login); static int key_login(pam_handle_t *pamh, int flags, PKCS11_SLOT *slot, const char *pin_regex) { char *password = NULL; int ok; if (0 == slot->token->loginRequired #ifdef HAVE_PKCS11_IS_LOGGED_IN || (0 == PKCS11_is_logged_in(slot, 0, &ok) && ok == 1) #endif ) { ok = 1; goto err; } ok = 0; /* try to get stored item */ if (PAM_SUCCESS == pam_get_item(pamh, PAM_AUTHTOK, (void *)&password) && NULL != password) { password = strdup(password); if (NULL == password) { pam_syslog(pamh, LOG_CRIT, "strdup() failed: %s", strerror(errno)); goto err; } } else { const char *pin_info; if (slot->token->userPinFinalTry) { pin_info = _(" (last try)"); } else { pin_info = ""; } if (0 != slot->token->secureLogin) { prompt(flags, pamh, PAM_TEXT_INFO, NULL, _("Login on PIN pad with %s%s"), slot->token->label, pin_info); } else { /* ask the user for the password if variable text is set */ if (PAM_SUCCESS != prompt(flags, pamh, PAM_PROMPT_ECHO_OFF, &password, _("Login with %s%s: "), slot->token->label, pin_info)) { goto err; } } } if (NULL != password && NULL != pin_regex && 0 < strlen(pin_regex)) { regex_t regex; int regex_compiled = 0; int result = 0; result = regcomp(®ex, pin_regex, REG_EXTENDED); if (0 == result) { regex_compiled = 1; result = regexec(®ex, password, 0, NULL, 0); } if (result) { char regex_error[256]; regerror(result, ®ex, regex_error, sizeof regex_error); pam_syslog(pamh, LOG_CRIT, "PIN regex didn't match: %s", regex_error); if (1 == regex_compiled) { regfree(®ex); } prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("Invalid PIN")); goto err; } regfree(®ex); } if (0 != PKCS11_login(slot, 0, password)) { if (slot->token->userPinLocked) { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PIN not verified; PIN locked")); } else if (slot->token->userPinFinalTry) { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PIN not verified; one try remaining")); } else { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PIN not verified")); } goto err; } pam_set_item(pamh, PAM_AUTHTOK, password); ok = 1; err: if (NULL != password) { OPENSSL_cleanse(password, strlen(password)); free(password); } return ok; } static int key_change_login(pam_handle_t *pamh, int flags, PKCS11_SLOT *slot, const char *pin_regex) { char *old = NULL, *new = NULL, *retyped = NULL; int ok; if (0 == slot->token->loginRequired) { /* we can't change a PIN */ ok = 0; goto err; } ok = 0; /* We need a R/W public session to change the PIN via PUK or * a R/W user session to change the PIN via PIN */ if (0 != PKCS11_open_session(slot, 1) || (0 == slot->token->userPinLocked && 1 != key_login(pamh, flags, slot, pin_regex))) { goto err; } /* prompt for new PIN (and PUK if needed) */ if (0 != slot->token->secureLogin) { if (0 != slot->token->userPinLocked) { prompt(flags, pamh, PAM_TEXT_INFO, NULL, _("Change PIN with PUK on PIN pad for %s"), slot->token->label); } else { prompt(flags, pamh, PAM_TEXT_INFO, NULL, _("Change PIN on PIN pad for %s"), slot->token->label); } } else { if (0 != slot->token->userPinLocked) { if (PAM_SUCCESS == prompt(flags, pamh, PAM_PROMPT_ECHO_OFF, &old, _("PUK for %s: "), slot->token->label)) { goto err; } } else { #ifdef TEST /* In the tests we're calling pam_sm_chauthtok() directly, so * pam_get_item(PAM_AUTHTOK) will return PAM_BAD_ITEM. As * workaround, we simply enter the current PIN twice. */ if (PAM_SUCCESS != prompt(flags, pamh, PAM_PROMPT_ECHO_OFF, &old, _("Current PIN: "))) { goto err; } #else if (PAM_SUCCESS != pam_get_item(pamh, PAM_AUTHTOK, (void *)&old) || NULL == old) { goto err; } old = strdup(old); if (NULL == old) { pam_syslog(pamh, LOG_CRIT, "strdup() failed: %s", strerror(errno)); goto err; } #endif } if (PAM_SUCCESS != prompt(flags, pamh, PAM_PROMPT_ECHO_OFF, &new, _("Enter new PIN: ")) || PAM_SUCCESS != prompt(flags, pamh, PAM_PROMPT_ECHO_OFF, &retyped, _("Retype new PIN: "))) { goto err; } if (0 != strcmp(new, retyped)) { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PINs don't match")); goto err; } } if (0 != PKCS11_change_pin(slot, old, new)) { if (slot->token->userPinLocked) { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PIN not changed; PIN locked")); } else if (slot->token->userPinFinalTry) { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PIN not changed; one try remaining")); } else { prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("PIN not changed")); } goto err; } pam_set_item(pamh, PAM_AUTHTOK, new); ok = 1; err: if (NULL != retyped) { OPENSSL_cleanse(retyped, strlen(retyped)); free(retyped); } if (NULL != new) { OPENSSL_cleanse(new, strlen(new)); free(new); } if (NULL != old) { OPENSSL_cleanse(old, strlen(old)); free(old); } return ok; } static int key_find(pam_handle_t *pamh, int flags, const char *user, PKCS11_CTX *ctx, PKCS11_SLOT *slots, unsigned int nslots, PKCS11_SLOT **authslot, PKCS11_KEY **authkey) { int token_found = 0; if (NULL == authslot || NULL == authkey) { return 0; } *authkey = NULL; *authslot = NULL; /* search all valuable slots for a key that is authorized by the user */ while (0 < nslots) { PKCS11_SLOT *slot = NULL; PKCS11_CERT *certs = NULL; #ifdef HAVE_PKCS11_ENUMERATE_PUBLIC_KEYS PKCS11_KEY *keys = NULL; #endif unsigned int count = 0; slot = PKCS11_find_token(ctx, slots, nslots); if (NULL == slot || NULL == slot->token) { break; } token_found = 1; if (slot->token->loginRequired && slot->token->userPinLocked) { pam_syslog(pamh, LOG_DEBUG, "%s: PIN locked", slot->token->label); continue; } pam_syslog(pamh, LOG_DEBUG, "Searching %s for keys", slot->token->label); #ifdef HAVE_PKCS11_ENUMERATE_PUBLIC_KEYS /* First, search all available public keys to allow using tokens * without certificates (e.g. OpenPGP card) */ if (0 == PKCS11_enumerate_public_keys(slot->token, &keys, &count)) { while (0 < count && NULL != keys) { EVP_PKEY *pubkey = PKCS11_get_public_key(keys); int r = match_user_opensc(pubkey, user); if (1 != r) { r = match_user_openssh(pubkey, user); } if (NULL != pubkey) { EVP_PKEY_free(pubkey); } if (1 == r) { *authkey = keys; *authslot = slot; pam_syslog(pamh, LOG_DEBUG, "Found %s", keys->label); return 1; } /* Try the next possible public key */ keys++; count--; } } #endif /* Next, search all certificates */ if (0 == PKCS11_enumerate_certs(slot->token, &certs, &count)) { while (0 < count && NULL != certs) { EVP_PKEY *pubkey = X509_get_pubkey(certs->x509); int r = match_user_opensc(pubkey, user); if (1 != r) { r = match_user_openssh(pubkey, user); } if (NULL != pubkey) { EVP_PKEY_free(pubkey); } if (1 == r) { *authkey = PKCS11_find_key(certs); if (NULL == *authkey) { continue; } *authslot = slot; pam_syslog(pamh, LOG_DEBUG, "Found %s", certs->label); return 1; } /* Try the next possible certificate */ certs++; count--; } } /* Try the next possible slot: PKCS11 slots are implemented as array, * so starting to look at slot++ and decrementing nslots accordingly * will search the rest of slots. */ slot++; nslots -= (slot - slots); slots = slot; pam_syslog(pamh, LOG_DEBUG, "No authorized key found"); } if (0 == token_found) { prompt(flags, pamh, PAM_ERROR_MSG , NULL, _("No token found")); } else { prompt(flags, pamh, PAM_ERROR_MSG , NULL, _("No authorized keys on token")); } return 0; } static int randomize(pam_handle_t *pamh, unsigned char *r, unsigned int r_len) { int ok = 0; int fd = open("/dev/urandom", O_RDONLY); if (0 <= fd && read(fd, r, r_len) == (ssize_t)r_len) { ok = 1; } else { pam_syslog(pamh, LOG_CRIT, "Error reading from /dev/urandom: %s", strerror(errno)); } if (0 <= fd) { close(fd); } return ok; } static int key_verify(pam_handle_t *pamh, int flags, PKCS11_KEY *authkey) { int ok = 0; unsigned char challenge[30]; unsigned char *signature = NULL; unsigned int siglen; const EVP_MD *md = EVP_sha1(); EVP_MD_CTX *md_ctx = EVP_MD_CTX_new(); EVP_PKEY *privkey = PKCS11_get_private_key(authkey); EVP_PKEY *pubkey = PKCS11_get_public_key(authkey); if (NULL == privkey) goto err; siglen = EVP_PKEY_size(privkey); if (siglen <= 0) goto err; signature = malloc(siglen); if (NULL == signature) goto err; /* Verify a SHA-1 hash of random data, signed by the key. * * Note that this will not work keys that aren't eligible for signing. * Unfortunately, libp11 currently has no way of checking * C_GetAttributeValue(CKA_SIGN), see * https://github.com/OpenSC/libp11/issues/219. Since we don't want to * implement try and error, we live with this limitation */ if (1 != randomize(pamh, challenge, sizeof challenge)) { goto err; } if (NULL == pubkey || NULL == privkey || NULL == md_ctx || NULL == md || !EVP_SignInit(md_ctx, md) || !EVP_SignUpdate(md_ctx, challenge, sizeof challenge) || !EVP_SignFinal(md_ctx, signature, &siglen, privkey) || !EVP_MD_CTX_reset(md_ctx) || !EVP_VerifyInit(md_ctx, md) || !EVP_VerifyUpdate(md_ctx, challenge, sizeof challenge) || 1 != EVP_VerifyFinal(md_ctx, signature, siglen, pubkey)) { pam_syslog(pamh, LOG_DEBUG, "Error verifying key: %s\n", ERR_reason_error_string(ERR_get_error())); prompt(flags, pamh, PAM_ERROR_MSG, NULL, _("Error verifying key")); goto err; } ok = 1; err: free(signature); if (NULL != pubkey) EVP_PKEY_free(pubkey); if (NULL != privkey) EVP_PKEY_free(privkey); if (NULL != md_ctx) { EVP_MD_CTX_free(md_ctx); } return ok; } PAM_EXTERN int pam_sm_authenticate(pam_handle_t * pamh, int flags, int argc, const char **argv) { int r; PKCS11_CTX *ctx; unsigned int nslots; PKCS11_KEY *authkey; PKCS11_SLOT *slots, *authslot; const char *user; const char *pin_regex; r = module_refresh(pamh, flags, argc, argv, &user, &ctx, &slots, &nslots, &pin_regex); if (PAM_SUCCESS != r) { goto err; } if (1 != key_find(pamh, flags, user, ctx, slots, nslots, &authslot, &authkey)) { r = PAM_AUTHINFO_UNAVAIL; goto err; } if (1 != key_login(pamh, flags, authslot, pin_regex) || 1 != key_verify(pamh, flags, authkey)) { if (authslot->token->userPinLocked) { r = PAM_MAXTRIES; } else { r = PAM_AUTH_ERR; } goto err; } r = PAM_SUCCESS; err: #ifdef TEST module_data_cleanup(pamh, global_module_data, r); #endif return r; } PAM_EXTERN int pam_sm_setcred(pam_handle_t * pamh, int flags, int argc, const char **argv) { /* Actually, we should return the same value as pam_sm_authenticate(). */ return PAM_SUCCESS; } PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t * pamh, int flags, int argc, const char **argv) { /* if the user has been authenticated (precondition of this call), then * everything is OK. Yes, we explicitly don't want to check CRLs, OCSP or * exparation of certificates (use pam_pkcs11 for this). */ return PAM_SUCCESS; } PAM_EXTERN int pam_sm_open_session(pam_handle_t * pamh, int flags, int argc, const char **argv) { pam_syslog(pamh, LOG_DEBUG, "Function pam_sm_open_session() is not implemented in this module"); return PAM_SERVICE_ERR; } PAM_EXTERN int pam_sm_close_session(pam_handle_t * pamh, int flags, int argc, const char **argv) { pam_syslog(pamh, LOG_DEBUG, "Function pam_sm_close_session() is not implemented in this module"); return PAM_SERVICE_ERR; } PAM_EXTERN int pam_sm_chauthtok(pam_handle_t * pamh, int flags, int argc, const char **argv) { int r; PKCS11_CTX *ctx; unsigned int nslots; PKCS11_KEY *authkey; PKCS11_SLOT *slots, *authslot; const char *user, *pin_regex; r = module_refresh(pamh, flags, argc, argv, &user, &ctx, &slots, &nslots, &pin_regex); if (PAM_SUCCESS != r) { goto err; } if (flags & PAM_CHANGE_EXPIRED_AUTHTOK) { /* Yes, we explicitly don't want to check CRLs, OCSP or exparation of * certificates (use pam_pkcs11 for this). */ r = PAM_SUCCESS; goto err; } if (1 != key_find(pamh, flags, user, ctx, slots, nslots, &authslot, &authkey)) { r = PAM_AUTHINFO_UNAVAIL; goto err; } if (flags & PAM_PRELIM_CHECK) { r = PAM_TRY_AGAIN; goto err; } if (flags & PAM_UPDATE_AUTHTOK) { if (1 != key_change_login(pamh, flags, authslot, pin_regex)) { if (authslot->token->userPinLocked) { r = PAM_MAXTRIES; } else { r = PAM_AUTH_ERR; } goto err; } } r = PAM_SUCCESS; err: #ifdef TEST module_data_cleanup(pamh, global_module_data, r); #endif return r; } #ifdef PAM_STATIC /* static module data */ struct pam_module _pam_group_modstruct = { PACKAGE, pam_sm_authenticate, pam_sm_setcred, pam_sm_acct_mgmt, pam_sm_open_session, pam_sm_close_session, pam_sm_chauthtok }; #endif pam_p11-pam_p11-0.3.1/src/pam_p11.exports000066400000000000000000000001561353625622400176720ustar00rootroot00000000000000pam_sm_authenticate pam_sm_setcred pam_sm_acct_mgmt pam_sm_open_session pam_sm_close_session pam_sm_chauthtok pam_p11-pam_p11-0.3.1/src/passwd.c000066400000000000000000000021411353625622400164470ustar00rootroot00000000000000/* * Copyright (C) 2018 Frank Morgner * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include extern int pam_sm_test(pam_handle_t *pamh, int flags, int argc, const char **argv); int pam_sm_test(pam_handle_t *pamh, int flags, int argc, const char **argv) { return pam_sm_chauthtok(pamh, PAM_UPDATE_AUTHTOK, argc, argv); } pam_p11-pam_p11-0.3.1/src/test.c000066400000000000000000000046211353625622400161320ustar00rootroot00000000000000/* * Copyright (C) 2018 Frank Morgner * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #include #include #include #include #include #include #ifdef HAVE_SECURITY_PAM_MISC_H #include #endif #ifndef LIBDIR #define LIBDIR "/usr/lib" #endif extern int pam_sm_test(pam_handle_t *pamh, int flags, int argc, const char **argv); int main(int argc, const char **argv) { char user[32]; char module[4096]; const char *pam_argv[] = { module, }; pam_handle_t *pamh = NULL; struct pam_conv conv = { #ifdef HAVE_OPENPAM_TTYCONV openpam_ttyconv, #else misc_conv, #endif NULL, }; int r; int status = EXIT_FAILURE; /* initialize default values */ strcpy(module, LIBDIR "/opensc-pkcs11.so"); if (0 != getlogin_r(user, sizeof user)) goto err; switch (argc) { case 3: strncpy(user, argv[2], (sizeof user) - 1); /* fall through */ case 2: strncpy(module, argv[1], (sizeof module) - 1); /* fall through */ case 1: break; default: printf("Usage: %s [pkcs11_module.so [username]]\n", argv[0]); /* fall through */ case 0: goto err; } module[(sizeof module) - 1] = '\0'; user[(sizeof user) - 1] = '\0'; printf("Using '%s' for '%s'\n", module, user); r = pam_start("test", user, &conv, &pamh); if (PAM_SUCCESS != r) goto pam_err; r = pam_sm_test(pamh, 0, sizeof pam_argv/sizeof *pam_argv, pam_argv); if (PAM_SUCCESS != r) goto pam_err; status = EXIT_SUCCESS; pam_err: if (PAM_SUCCESS != r) { printf("Error: %s\n", pam_strerror(pamh, r)); } else { printf("OK\n"); } pam_end(pamh, r); err: exit(status); }