├── ChangeLog ├── src ├── versioninfo.rc.in ├── cryptoki.h ├── p11-logout.c ├── p11-cancelfunction.c ├── p11-getfunctionstatus.c ├── p11-digestkey.c ├── p11-digestinit.c ├── p11-seedrandom.c ├── p11-initpin.c ├── p11-destroyobject.c ├── p11-signupdate.c ├── p11-digestupdate.c ├── p11-verifyupdate.c ├── p11-verifyinit.c ├── p11-digestfinal.c ├── p11-getobjectsize.c ├── p11-signfinal.c ├── p11-verifyfinal.c ├── p11-login.c ├── p11-encryptinit.c ├── p11-inittoken.c ├── p11-signrecoverinit.c ├── p11-verifyrecoverinit.c ├── p11-waitforslotevent.c ├── p11-decryptfinal.c ├── p11-encryptfinal.c ├── error-mapping.h ├── p11-createobject.c ├── p11-getoperationstate.c ├── options.h ├── p11-digest.c ├── p11-setattributevalue.c ├── p11-verify.c ├── p11-setpin.c ├── p11-encrypt.c ├── p11-signrecover.c ├── p11-copyobject.c ├── p11-generatekey.c ├── p11-verifyrecover.c ├── p11-encryptupdate.c ├── p11-decryptupdate.c ├── p11-decryptdigestupdate.c ├── p11-decryptverifyupdate.c ├── p11-wrapkey.c ├── p11-derivekey.c ├── p11-signencryptupdate.c ├── p11-digestencryptupdate.c ├── p11-closeallsessions.c ├── p11-setoperationstate.c ├── dllmain.c ├── p11-closesession.c ├── debug.h ├── p11-unwrapkey.c ├── p11-findobjectsfinal.c ├── p11-finalize.c ├── p11-getinfo.c ├── p11-generatekeypair.c ├── p11-getmechanisminfo.c ├── p11-generaterandom.c ├── p11-decryptinit.c ├── p11-signinit.c ├── gpgsm.h ├── p11-opensession.c ├── error-mapping.c ├── locking.h ├── p11-findobjects.c ├── p11-getslotinfo.c ├── p11-getmechanismlist.c ├── settings.h ├── p11-getsessioninfo.c ├── p11-sign.c ├── p11-getattributevalue.c ├── locking.c ├── p11-decrypt.c ├── libscute.vers ├── scute.def ├── p11-getslotlist.c ├── table.h ├── agent.h ├── support.h ├── debug.c ├── p11-initialize.c ├── p11-gettokeninfo.c ├── p11-getfunctionlist.c ├── p11-findobjectsinit.c └── sexp-parse.h ├── doc ├── images │ ├── firefox-cm.png │ ├── firefox-pref.png │ ├── firefox-bad-pin.png │ ├── firefox-cm-view.png │ ├── firefox-dm-load.png │ ├── firefox-pref-view.png │ ├── firefox-dm-load-after.png │ ├── firefox-cm-view-detail.png │ ├── firefox-dm-load-before.png │ ├── firefox-dm-token-present.png │ ├── thunderbird-smime-button.png │ ├── libreoffice-pdf-signature.png │ ├── thunderbird-account-settings.png │ ├── libreoffice-digital-signatures.png │ └── libreoffice-certificate-selection.png └── Makefile.am ├── m4 ├── Makefile.am ├── ltversion.m4 └── autobuild.m4 ├── .gitignore ├── autogen.rc ├── tests ├── clean-socketdir ├── t-initialize.c ├── Makefile.am ├── t-getinfo.c ├── t-getmechanismlist.c ├── t-closeallsessions.c ├── t-getslotlist.c ├── t-generaterandom.c ├── t-opensession.c ├── t-link.c ├── t-getsessioninfo.c ├── t-getfunctionlist.c ├── t-getmechanisminfo.c └── t-auth.c ├── AUTHORS ├── README.GIT ├── Makefile.am ├── NEWS └── TODO /ChangeLog: -------------------------------------------------------------------------------- 1 | Dummy ChangeLog - the old one is build-aus/git-log-footer 2 | -------------------------------------------------------------------------------- /src/versioninfo.rc.in: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/src/versioninfo.rc.in -------------------------------------------------------------------------------- /doc/images/firefox-cm.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-cm.png -------------------------------------------------------------------------------- /doc/images/firefox-pref.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-pref.png -------------------------------------------------------------------------------- /doc/images/firefox-bad-pin.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-bad-pin.png -------------------------------------------------------------------------------- /doc/images/firefox-cm-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-cm-view.png -------------------------------------------------------------------------------- /doc/images/firefox-dm-load.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-dm-load.png -------------------------------------------------------------------------------- /doc/images/firefox-pref-view.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-pref-view.png -------------------------------------------------------------------------------- /doc/images/firefox-dm-load-after.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-dm-load-after.png -------------------------------------------------------------------------------- /doc/images/firefox-cm-view-detail.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-cm-view-detail.png -------------------------------------------------------------------------------- /doc/images/firefox-dm-load-before.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-dm-load-before.png -------------------------------------------------------------------------------- /doc/images/firefox-dm-token-present.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/firefox-dm-token-present.png -------------------------------------------------------------------------------- /doc/images/thunderbird-smime-button.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/thunderbird-smime-button.png -------------------------------------------------------------------------------- /doc/images/libreoffice-pdf-signature.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/libreoffice-pdf-signature.png -------------------------------------------------------------------------------- /doc/images/thunderbird-account-settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/thunderbird-account-settings.png -------------------------------------------------------------------------------- /doc/images/libreoffice-digital-signatures.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/libreoffice-digital-signatures.png -------------------------------------------------------------------------------- /doc/images/libreoffice-certificate-selection.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gpg/scute/HEAD/doc/images/libreoffice-certificate-selection.png -------------------------------------------------------------------------------- /m4/Makefile.am: -------------------------------------------------------------------------------- 1 | EXTRA_DIST = autobuild.m4 gpg-error.m4 libassuan.m4 libtool.m4 \ 2 | ltoptions.m4 ltsugar.m4 ltversion.m4 lt~obsolete.m4 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | Makefile.in 2 | aclocal.m4 3 | autom4te.cache/ 4 | config.h.in 5 | configure 6 | doc/Makefile.in 7 | doc/scute.info 8 | doc/stamp-vti 9 | doc/version.texi 10 | m4/Makefile.in 11 | obj/ 12 | src/Makefile.in 13 | tests/Makefile.in 14 | /VERSION 15 | -------------------------------------------------------------------------------- /autogen.rc: -------------------------------------------------------------------------------- 1 | # autogen.sh configuration for Scute -*- sh -*- 2 | case "$myhost" in 3 | w32) 4 | configure_opts=" 5 | --with-gpg-error-prefix=@SYSROOT@ 6 | --with-libassuan-prefix=@SYSROOT@ 7 | " 8 | ;; 9 | 10 | amd64) 11 | configure_opts=" 12 | --with-gpg-error-prefix=@SYSROOT@ 13 | --with-libassuan-prefix=@SYSROOT@ 14 | " 15 | ;; 16 | esac 17 | 18 | extra_aclocal_flags="" 19 | final_info="./configure --enable-maintainer-mode && make" 20 | -------------------------------------------------------------------------------- /tests/clean-socketdir: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # We do the clean-up only when the tests are run with GNUPGHOME 4 | # set to the tests directory (which is the default). If the user 5 | # saw fit to override TESTS_ENVIRONMENT to use another home, we 6 | # must assume she knows what she is doing. 7 | [ "$GNUPGHOME" = "$HOME/.gnupg" ] && exit 0 8 | 9 | if [ "$GNUPGHOME" = "`/bin/pwd`" ]; then 10 | socketdir=`gpgconf --list-dirs socketdir` 11 | if [ -d "$socketdir" ]; then 12 | rm -f $socketdir/S.* 13 | rmdir $socketdir || true 14 | fi 15 | 16 | rm -f pubring.kbx reader_*.status 17 | if [ -d private-keys-v1.d ]; then 18 | rm -f private-keys-v1.d/*.key 19 | rmdir private-keys-v1.d 20 | fi 21 | fi 22 | -------------------------------------------------------------------------------- /m4/ltversion.m4: -------------------------------------------------------------------------------- 1 | # ltversion.m4 -- version numbers -*- Autoconf -*- 2 | # 3 | # Copyright (C) 2004 Free Software Foundation, Inc. 4 | # Written by Scott James Remnant, 2004 5 | # 6 | # This file is free software; the Free Software Foundation gives 7 | # unlimited permission to copy and/or distribute it, with or without 8 | # modifications, as long as this notice is preserved. 9 | 10 | # @configure_input@ 11 | 12 | # serial 3337 ltversion.m4 13 | # This file is part of GNU Libtool 14 | 15 | m4_define([LT_PACKAGE_VERSION], [2.4.2]) 16 | m4_define([LT_PACKAGE_REVISION], [1.3337]) 17 | 18 | AC_DEFUN([LTVERSION_VERSION], 19 | [macro_version='2.4.2' 20 | macro_revision='1.3337' 21 | _LT_DECL(, macro_version, 0, [Which release of libtool.m4 was used?]) 22 | _LT_DECL(, macro_revision, 0) 23 | ]) 24 | -------------------------------------------------------------------------------- /src/cryptoki.h: -------------------------------------------------------------------------------- 1 | /* cryptoki.h - A wrapper for the cryptoki interface. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef _CRYPTOKI_H_ 22 | #define _CRYPTOKI_H_ 1 23 | 24 | 25 | #define CRYPTOKI_EXPORTS 26 | #include "pkcs11.h" 27 | 28 | #endif /* !_CRYPTOKI_H_ */ 29 | -------------------------------------------------------------------------------- /src/p11-logout.c: -------------------------------------------------------------------------------- 1 | /* p11-logout.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_Logout (CK_SESSION_HANDLE hSession) 30 | { 31 | (void) hSession; 32 | return CKR_FUNCTION_NOT_SUPPORTED; 33 | } 34 | -------------------------------------------------------------------------------- /src/p11-cancelfunction.c: -------------------------------------------------------------------------------- 1 | /* p11-cancelfunction.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_CancelFunction (CK_SESSION_HANDLE hSession) 30 | { 31 | (void) hSession; 32 | return CKR_FUNCTION_NOT_PARALLEL; 33 | } 34 | -------------------------------------------------------------------------------- /src/p11-getfunctionstatus.c: -------------------------------------------------------------------------------- 1 | /* p11-getfunctionstatus.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_GetFunctionStatus (CK_SESSION_HANDLE hSession) 30 | { 31 | (void) hSession; 32 | return CKR_FUNCTION_NOT_PARALLEL; 33 | } 34 | -------------------------------------------------------------------------------- /src/p11-digestkey.c: -------------------------------------------------------------------------------- 1 | /* p11-digestkey.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | CK_RV CK_SPEC 28 | C_DigestKey (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hKey) 29 | { 30 | (void) hSession; 31 | (void) hKey; 32 | return CKR_FUNCTION_NOT_SUPPORTED; 33 | } 34 | -------------------------------------------------------------------------------- /src/p11-digestinit.c: -------------------------------------------------------------------------------- 1 | /* p11-digestinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DigestInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism) 30 | { 31 | (void) hSession; 32 | (void) pMechanism; 33 | return CKR_FUNCTION_NOT_SUPPORTED; 34 | } 35 | -------------------------------------------------------------------------------- /src/p11-seedrandom.c: -------------------------------------------------------------------------------- 1 | /* p11-seedrandom.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SeedRandom (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, CK_ULONG ulSeedLen) 30 | { 31 | (void) hSession; 32 | (void) pSeed; 33 | (void) ulSeedLen; 34 | return CKR_OK; 35 | } 36 | -------------------------------------------------------------------------------- /tests/t-initialize.c: -------------------------------------------------------------------------------- 1 | /* t-initialize.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | int 27 | main (int argc, char *argv[]) 28 | { 29 | CK_RV err; 30 | 31 | (void) argc; 32 | (void) argv; 33 | 34 | init_cryptoki (); 35 | 36 | err = C_Finalize (NULL); 37 | fail_if_err (err); 38 | 39 | return 0; 40 | } 41 | -------------------------------------------------------------------------------- /src/p11-initpin.c: -------------------------------------------------------------------------------- 1 | /* p11-initpin.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_InitPIN (CK_SESSION_HANDLE hSession, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) 30 | { 31 | (void) hSession; 32 | (void) pPin; 33 | (void) ulPinLen; 34 | return CKR_FUNCTION_NOT_SUPPORTED; 35 | } 36 | -------------------------------------------------------------------------------- /src/p11-destroyobject.c: -------------------------------------------------------------------------------- 1 | /* p11-destroyobject.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | CK_RV CK_SPEC 28 | C_DestroyObject (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) 29 | { 30 | /* FIXME: Implement this. */ 31 | (void) hSession; 32 | (void) hObject; 33 | return CKR_FUNCTION_NOT_SUPPORTED; 34 | } 35 | -------------------------------------------------------------------------------- /src/p11-signupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-signupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SignUpdate (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, CK_ULONG ulPartLen) 30 | { 31 | (void) hSession; 32 | (void) pPart; 33 | (void) ulPartLen; 34 | return CKR_FUNCTION_NOT_SUPPORTED; 35 | } 36 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Package: scute 2 | Maintainer: Damien Goutte-Gattat 3 | Bug reports: https://bugs.gnupg.org/ 4 | Security related bug reports: security@gnupg.org 5 | License: LGPL-2.1-or-later 6 | 7 | 8 | List of Copyright holders 9 | ========================= 10 | 11 | g10 Code GmbH 12 | - Design and implementation 13 | 14 | Andreas Jellinghaus 15 | - Contributions to src/pkcs11.h. 16 | 17 | Alon Bar-Lev 18 | - Contributions to src/pkcs11.h. 19 | 20 | Damien Goutte-Gattat 21 | - Various changes. 22 | 23 | 24 | Authors with a DCO 25 | ================== 26 | 27 | Jernej Jakob 28 | 2023-06-28:<20230628155639.14869c41@gentoo.home>: 29 | 30 | 31 | Copyright 2006, 2008 g10 Code GmbH 32 | 33 | This file is free software; as a special exception the author gives 34 | unlimited permission to copy and/or distribute it, with or without 35 | modifications, as long as this notice is preserved. 36 | 37 | This file is distributed in the hope that it will be useful, but 38 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 39 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 40 | -------------------------------------------------------------------------------- /src/p11-digestupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-digestupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | CK_RV CK_SPEC 28 | C_DigestUpdate (CK_SESSION_HANDLE hSession, 29 | CK_BYTE_PTR pPart, CK_ULONG ulPartLen) 30 | { 31 | (void) hSession; 32 | (void) pPart; 33 | (void) ulPartLen; 34 | return CKR_FUNCTION_NOT_SUPPORTED; 35 | } 36 | -------------------------------------------------------------------------------- /src/p11-verifyupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-verifyupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_VerifyUpdate (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pPart, CK_ULONG ulPartLen) 31 | { 32 | (void) hSession; 33 | (void) pPart; 34 | (void) ulPartLen; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-verifyinit.c: -------------------------------------------------------------------------------- 1 | /* p11-verifyinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_VerifyInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_OBJECT_HANDLE hKey) 31 | { 32 | (void) hSession; 33 | (void) pMechanism; 34 | (void) hKey; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-digestfinal.c: -------------------------------------------------------------------------------- 1 | /* p11-digestfinal.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DigestFinal (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen) 31 | { 32 | (void) hSession; 33 | (void) pDigest; 34 | (void) pulDigestLen; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-getobjectsize.c: -------------------------------------------------------------------------------- 1 | /* p11-getobjectsize.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_GetObjectSize (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, 30 | CK_ULONG_PTR pulSize) 31 | { 32 | (void) hSession; 33 | (void) hObject; 34 | (void) pulSize; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-signfinal.c: -------------------------------------------------------------------------------- 1 | /* p11-signfinal.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SignFinal (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) 31 | { 32 | (void) hSession; 33 | (void) pSignature; 34 | (void) pulSignatureLen; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-verifyfinal.c: -------------------------------------------------------------------------------- 1 | /* p11-verifyfinal.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_VerifyFinal (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen) 31 | { 32 | (void) hSession; 33 | (void) pSignature; 34 | (void) ulSignatureLen; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-login.c: -------------------------------------------------------------------------------- 1 | /* p11-login.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_Login (CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, 30 | CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen) 31 | { 32 | (void) hSession; 33 | (void) userType; 34 | (void) pPin; 35 | (void) ulPinLen; 36 | return CKR_FUNCTION_NOT_SUPPORTED; 37 | } 38 | -------------------------------------------------------------------------------- /src/p11-encryptinit.c: -------------------------------------------------------------------------------- 1 | /* p11-encryptinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | CK_RV CK_SPEC 28 | C_EncryptInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 29 | CK_OBJECT_HANDLE hKey) 30 | { 31 | (void) hSession; 32 | (void) pMechanism; 33 | (void) hKey; 34 | 35 | 36 | 37 | 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-inittoken.c: -------------------------------------------------------------------------------- 1 | /* p11-inittoken.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_InitToken (CK_SLOT_ID slotID, CK_UTF8CHAR_PTR pPin, CK_ULONG ulPinLen, 30 | CK_UTF8CHAR_PTR pLabel) 31 | { 32 | (void) slotID; 33 | (void) pPin; 34 | (void) ulPinLen; 35 | (void) pLabel; 36 | return CKR_FUNCTION_NOT_SUPPORTED; 37 | } 38 | -------------------------------------------------------------------------------- /src/p11-signrecoverinit.c: -------------------------------------------------------------------------------- 1 | /* p11-signrecoverinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SignRecoverInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_OBJECT_HANDLE hKey) 31 | { 32 | (void) hSession; 33 | (void) pMechanism; 34 | (void) hKey; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-verifyrecoverinit.c: -------------------------------------------------------------------------------- 1 | /* p11-verifyrecoverinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_VerifyRecoverInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_OBJECT_HANDLE hKey) 31 | { 32 | (void) hSession; 33 | (void) pMechanism; 34 | (void) hKey; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-waitforslotevent.c: -------------------------------------------------------------------------------- 1 | /* p11-waitforslotevent.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_WaitForSlotEvent (CK_FLAGS flags, CK_SLOT_ID_PTR pSlot, CK_VOID_PTR pReserved) 30 | { 31 | /* See the TODO file why this is not implemented. */ 32 | (void) flags; 33 | (void) pSlot; 34 | (void) pReserved; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/p11-decryptfinal.c: -------------------------------------------------------------------------------- 1 | /* p11-decryptfinal.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DecryptFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pLastPart, 30 | CK_ULONG_PTR pulLastPartLen) 31 | { 32 | /* FIXME: Implement this. */ 33 | (void) hSession; 34 | (void) pLastPart; 35 | (void) pulLastPartLen; 36 | return CKR_FUNCTION_NOT_SUPPORTED; 37 | } 38 | -------------------------------------------------------------------------------- /src/p11-encryptfinal.c: -------------------------------------------------------------------------------- 1 | /* p11-encryptfinal.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_EncryptFinal (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pLastEncryptedPart, 30 | CK_ULONG_PTR pulLastEncryptedPartLen) 31 | { 32 | (void) hSession; 33 | (void) pLastEncryptedPart; 34 | (void) pulLastEncryptedPartLen; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /m4/autobuild.m4: -------------------------------------------------------------------------------- 1 | # autobuild.m4 serial 2 (autobuild-3.3) 2 | # Copyright (C) 2004 Simon Josefsson 3 | # 4 | # This file is free software, distributed under the terms of the GNU 5 | # General Public License. As a special exception to the GNU General 6 | # Public License, this file may be distributed as part of a program 7 | # that contains a configuration script generated by Autoconf, under 8 | # the same distribution terms as the rest of that program. 9 | # 10 | # This file can can be used in projects which are not available under 11 | # the GNU General Public License or the GNU Library General Public 12 | # License but which still want to provide support for Autobuild. 13 | 14 | # Usage: AB_INIT([MODE]). 15 | AC_DEFUN([AB_INIT], 16 | [ 17 | AC_REQUIRE([AC_CANONICAL_BUILD]) 18 | AC_REQUIRE([AC_CANONICAL_HOST]) 19 | 20 | AC_MSG_NOTICE([autobuild project... ${PACKAGE_NAME:-$PACKAGE}]) 21 | AC_MSG_NOTICE([autobuild revision... ${PACKAGE_VERSION:-$VERSION}]) 22 | hostname=`hostname` 23 | if test "$hostname"; then 24 | AC_MSG_NOTICE([autobuild hostname... $hostname]) 25 | fi 26 | ifelse([$1],[],,[AC_MSG_NOTICE([autobuild mode... $1])]) 27 | date=`date +%Y%m%d-%H%M%S` 28 | if test "$?" != 0; then 29 | date=`date` 30 | fi 31 | if test "$date"; then 32 | AC_MSG_NOTICE([autobuild timestamp... $date]) 33 | fi 34 | ]) 35 | -------------------------------------------------------------------------------- /src/error-mapping.h: -------------------------------------------------------------------------------- 1 | /* error-mapping.c - Scute error mapping interface. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef ERROR_MAPPING_H 22 | #define ERROR_MAPPING_H 1 23 | 24 | #include 25 | 26 | #include 27 | 28 | #include "cryptoki.h" 29 | 30 | /* Map a system error code to a cryptoki return value. */ 31 | CK_RV scute_sys_to_ck (int err); 32 | 33 | /* Map a GnuPG error code to a cryptoki return value. */ 34 | CK_RV scute_gpg_err_to_ck (gpg_error_t err); 35 | 36 | #endif /* !ERROR_MAPPING_H */ 37 | -------------------------------------------------------------------------------- /src/p11-createobject.c: -------------------------------------------------------------------------------- 1 | /* p11-createobject.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_CreateObject (CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, 30 | CK_ULONG ulCount, CK_OBJECT_HANDLE_PTR phObject) 31 | { 32 | (void) hSession; 33 | (void) pTemplate; 34 | (void) ulCount; 35 | (void) phObject; 36 | return CKR_FUNCTION_NOT_SUPPORTED; 37 | } 38 | -------------------------------------------------------------------------------- /src/p11-getoperationstate.c: -------------------------------------------------------------------------------- 1 | /* p11-getoperationstate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_GetOperationState (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pOperationState, 30 | CK_ULONG_PTR pulOperationStateLen) 31 | { 32 | (void) hSession; 33 | (void) pOperationState; 34 | (void) pulOperationStateLen; 35 | return CKR_FUNCTION_NOT_SUPPORTED; 36 | } 37 | -------------------------------------------------------------------------------- /src/options.h: -------------------------------------------------------------------------------- 1 | /* options.h - Global options. 2 | * Copyright (C) 2020 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef OPTIONS_H 22 | #define OPTIONS_H 1 23 | 24 | /* Global options. */ 25 | typedef struct { 26 | char *user; 27 | int debug_flags; 28 | int only_marked; 29 | int assume_single_threaded; 30 | int no_autostart; /* Do not autostart gpg-agent. */ 31 | int no_chain; 32 | } _scute_opt_t; 33 | 34 | extern _scute_opt_t _scute_opt; 35 | 36 | 37 | /*-- readconf.c --*/ 38 | void _scute_read_conf (void); 39 | 40 | 41 | #endif /*OPTIONS_H*/ 42 | -------------------------------------------------------------------------------- /src/p11-digest.c: -------------------------------------------------------------------------------- 1 | /* p11-digest.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_Digest (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, 30 | CK_BYTE_PTR pDigest, CK_ULONG_PTR pulDigestLen) 31 | { 32 | (void) hSession; 33 | (void) pData; 34 | (void) ulDataLen; 35 | (void) pDigest; 36 | (void) pulDigestLen; 37 | return CKR_FUNCTION_NOT_SUPPORTED; 38 | } 39 | -------------------------------------------------------------------------------- /src/p11-setattributevalue.c: -------------------------------------------------------------------------------- 1 | /* p11-setattributevalue.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SetAttributeValue (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, 30 | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) 31 | { 32 | (void) hSession; 33 | (void) hObject; 34 | (void) pTemplate; 35 | (void) ulCount; 36 | return CKR_FUNCTION_NOT_SUPPORTED; 37 | } 38 | -------------------------------------------------------------------------------- /src/p11-verify.c: -------------------------------------------------------------------------------- 1 | /* p11-verify.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_Verify (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, 30 | CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen) 31 | { 32 | (void) hSession; 33 | (void) pData; 34 | (void) ulDataLen; 35 | (void) pSignature; 36 | (void) ulSignatureLen; 37 | return CKR_FUNCTION_NOT_SUPPORTED; 38 | } 39 | -------------------------------------------------------------------------------- /src/p11-setpin.c: -------------------------------------------------------------------------------- 1 | /* p11-setpin.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SetPIN (CK_SESSION_HANDLE hSession, 30 | CK_UTF8CHAR_PTR pOldPin, CK_ULONG ulOldLen, 31 | CK_UTF8CHAR_PTR pNewPin, CK_ULONG ulNewLen) 32 | { 33 | (void) hSession; 34 | (void) pOldPin; 35 | (void) ulOldLen; 36 | (void) pNewPin; 37 | (void) ulNewLen; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-encrypt.c: -------------------------------------------------------------------------------- 1 | /* p11-encrypt.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_Encrypt (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, 30 | CK_BYTE_PTR pEncryptedData, CK_ULONG_PTR pulEncryptedDataLen) 31 | { 32 | (void) hSession; 33 | (void) pData; 34 | (void) ulDataLen; 35 | (void) pEncryptedData; 36 | (void) pulEncryptedDataLen; 37 | return CKR_FUNCTION_NOT_SUPPORTED; 38 | } 39 | -------------------------------------------------------------------------------- /src/p11-signrecover.c: -------------------------------------------------------------------------------- 1 | /* p11-signrecover.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SignRecover (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pData, CK_ULONG ulDataLen, 31 | CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) 32 | { 33 | (void) hSession; 34 | (void) pData; 35 | (void) ulDataLen; 36 | (void) pSignature; 37 | (void) pulSignatureLen; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-copyobject.c: -------------------------------------------------------------------------------- 1 | /* p11-copyobject.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_CopyObject (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, 30 | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, 31 | CK_OBJECT_HANDLE_PTR phNewObject) 32 | { 33 | (void) hSession; 34 | (void) hObject; 35 | (void) pTemplate; 36 | (void) ulCount; 37 | (void) phNewObject; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-generatekey.c: -------------------------------------------------------------------------------- 1 | /* p11-generatekey.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_GenerateKey (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount, 31 | CK_OBJECT_HANDLE_PTR phKey) 32 | { 33 | (void) hSession; 34 | (void) pMechanism; 35 | (void) pTemplate; 36 | (void) ulCount; 37 | (void) phKey; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-verifyrecover.c: -------------------------------------------------------------------------------- 1 | /* p11-verifyrecover.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_VerifyRecover (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pSignature, CK_ULONG ulSignatureLen, 31 | CK_BYTE_PTR pData, CK_ULONG_PTR pulDataLen) 32 | { 33 | (void) hSession; 34 | (void) pSignature; 35 | (void) ulSignatureLen; 36 | (void) pData; 37 | (void) pulDataLen; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-encryptupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-encryptupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | CK_RV CK_SPEC 28 | C_EncryptUpdate (CK_SESSION_HANDLE hSession, 29 | CK_BYTE_PTR pPart, CK_ULONG ulPartLen, 30 | CK_BYTE_PTR pEncryptedPart, CK_ULONG_PTR pulEncryptedPartLen) 31 | { 32 | (void) hSession; 33 | (void) pPart; 34 | (void) ulPartLen; 35 | (void) pEncryptedPart; 36 | (void) pulEncryptedPartLen; 37 | return CKR_FUNCTION_NOT_SUPPORTED; 38 | } 39 | -------------------------------------------------------------------------------- /src/p11-decryptupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-decryptupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DecryptUpdate (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pEncryptedPart,CK_ULONG ulEncryptedPartLen, 31 | CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen) 32 | { 33 | (void) hSession; 34 | (void) pEncryptedPart; 35 | (void) ulEncryptedPartLen; 36 | (void) pPart; 37 | (void) pulPartLen; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-decryptdigestupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-decryptdigestupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DecryptDigestUpdate (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, 31 | CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen) 32 | { 33 | (void) hSession; 34 | (void) pEncryptedPart; 35 | (void) ulEncryptedPartLen; 36 | (void) pPart; 37 | (void) pulPartLen; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-decryptverifyupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-decryptverifyupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DecryptVerifyUpdate (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pEncryptedPart, CK_ULONG ulEncryptedPartLen, 31 | CK_BYTE_PTR pPart, CK_ULONG_PTR pulPartLen) 32 | { 33 | (void) hSession; 34 | (void) pEncryptedPart; 35 | (void) ulEncryptedPartLen; 36 | (void) pPart; 37 | (void) pulPartLen; 38 | return CKR_FUNCTION_NOT_SUPPORTED; 39 | } 40 | -------------------------------------------------------------------------------- /src/p11-wrapkey.c: -------------------------------------------------------------------------------- 1 | /* p11-wrapkey.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_WrapKey (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_OBJECT_HANDLE hWrappingKey, CK_OBJECT_HANDLE hKey, 31 | CK_BYTE_PTR pWrappedKey, CK_ULONG_PTR pulWrappedKeyLen) 32 | { 33 | (void) hSession; 34 | (void) pMechanism; 35 | (void) hWrappingKey; 36 | (void) hKey; 37 | (void) pWrappedKey; 38 | (void) pulWrappedKeyLen; 39 | return CKR_FUNCTION_NOT_SUPPORTED; 40 | } 41 | -------------------------------------------------------------------------------- /src/p11-derivekey.c: -------------------------------------------------------------------------------- 1 | /* p11-derivekey.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DeriveKey (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_OBJECT_HANDLE hBaseKey, CK_ATTRIBUTE_PTR pTemplate, 31 | CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey) 32 | { 33 | (void) hSession; 34 | (void) pMechanism; 35 | (void) hBaseKey; 36 | (void) pTemplate; 37 | (void) ulAttributeCount; 38 | (void) phKey; 39 | return CKR_FUNCTION_NOT_SUPPORTED; 40 | } 41 | -------------------------------------------------------------------------------- /src/p11-signencryptupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-signencryptupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SignEncryptUpdate (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pPart, CK_ULONG ulPartLen, 31 | CK_BYTE_PTR pEncryptedPart, 32 | CK_ULONG_PTR pulEncryptedPartLen) 33 | { 34 | (void) hSession; 35 | (void) pPart; 36 | (void) ulPartLen; 37 | (void) pEncryptedPart; 38 | (void) pulEncryptedPartLen; 39 | return CKR_FUNCTION_NOT_SUPPORTED; 40 | } 41 | -------------------------------------------------------------------------------- /src/p11-digestencryptupdate.c: -------------------------------------------------------------------------------- 1 | /* p11-digestencryptupdate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_DigestEncryptUpdate (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pPart, CK_ULONG ulPartLen, 31 | CK_BYTE_PTR pEncryptedPart, 32 | CK_ULONG_PTR pulEncryptedPartLen) 33 | { 34 | (void) hSession; 35 | (void) pPart; 36 | (void) ulPartLen; 37 | (void) pEncryptedPart; 38 | (void) pulEncryptedPartLen; 39 | return CKR_FUNCTION_NOT_SUPPORTED; 40 | } 41 | -------------------------------------------------------------------------------- /src/p11-closeallsessions.c: -------------------------------------------------------------------------------- 1 | /* p11-closeallsessions.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | CK_RV CK_SPEC 32 | C_CloseAllSessions (CK_SLOT_ID slotID) 33 | { 34 | CK_RV err = CKR_OK; 35 | slot_iterator_t slot; 36 | 37 | err = scute_global_lock (); 38 | if (err) 39 | return err; 40 | 41 | err = slots_lookup (slotID, &slot); 42 | if (err) 43 | goto out; 44 | 45 | err = slot_close_all_sessions (slot); 46 | 47 | out: 48 | scute_global_unlock (); 49 | return err; 50 | } 51 | -------------------------------------------------------------------------------- /src/p11-setoperationstate.c: -------------------------------------------------------------------------------- 1 | /* p11-setoperationstate.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_SetOperationState (CK_SESSION_HANDLE hSession, 30 | CK_BYTE_PTR pOperationState, CK_ULONG ulOperationStateLen, 31 | CK_OBJECT_HANDLE hEncryptionKey, 32 | CK_OBJECT_HANDLE hAuthenticationKey) 33 | { 34 | (void) hSession; 35 | (void) pOperationState; 36 | (void) ulOperationStateLen; 37 | (void) hEncryptionKey; 38 | (void) hAuthenticationKey; 39 | return CKR_FUNCTION_NOT_SUPPORTED; 40 | } 41 | -------------------------------------------------------------------------------- /src/dllmain.c: -------------------------------------------------------------------------------- 1 | /* dllmain.c - DLL entry point (Windows) 2 | * Copyright (C) 2007 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | #include 29 | 30 | #include 31 | #include 32 | 33 | 34 | /* Entry point called by DLL loader. */ 35 | STDAPI 36 | DllMain (HINSTANCE hinst, DWORD reason, LPVOID reserved) 37 | { 38 | if (reason == DLL_PROCESS_ATTACH) 39 | { 40 | WSADATA wsadat; 41 | 42 | WSAStartup (0x202, &wsadat); 43 | } 44 | else if (reason == DLL_PROCESS_DETACH) 45 | { 46 | WSACleanup (); 47 | } 48 | 49 | return TRUE; 50 | } 51 | -------------------------------------------------------------------------------- /src/p11-closesession.c: -------------------------------------------------------------------------------- 1 | /* p11-closesession.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | CK_RV CK_SPEC 32 | C_CloseSession (CK_SESSION_HANDLE hSession) 33 | { 34 | CK_RV err = CKR_OK; 35 | slot_iterator_t slot; 36 | session_iterator_t session; 37 | 38 | err = scute_global_lock (); 39 | if (err) 40 | return err; 41 | 42 | err = slots_lookup_session (hSession, &slot, &session); 43 | if (err) 44 | goto out; 45 | 46 | err = slot_close_session (slot, session); 47 | 48 | out: 49 | scute_global_unlock (); 50 | return err; 51 | } 52 | -------------------------------------------------------------------------------- /src/debug.h: -------------------------------------------------------------------------------- 1 | /* debug.c - Debug interface. 2 | * Copyright (C) 2006, 2008 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef DEBUG_H 22 | #define DEBUG_H 1 23 | 24 | #include 25 | #include "options.h" 26 | 27 | #define DEBUG_PREFIX "scute: " 28 | 29 | #define DBG_CRIT 0 30 | #define DBG_INFO (1 << 0) 31 | #define DBG_ASSUAN (1 << 1) 32 | 33 | extern FILE *_scute_debug_stream; 34 | 35 | #define DEBUG(flag, format, ...) \ 36 | do \ 37 | { \ 38 | if ((_scute_opt.debug_flags & (flag)) || flag == DBG_CRIT) \ 39 | fprintf (_scute_debug_stream, DEBUG_PREFIX "%s:%d: " format "\n", \ 40 | __func__, __LINE__, ##__VA_ARGS__); \ 41 | } \ 42 | while (0) 43 | 44 | void _scute_debug_init (void); 45 | 46 | 47 | #endif /* !DEBUG_H */ 48 | -------------------------------------------------------------------------------- /src/p11-unwrapkey.c: -------------------------------------------------------------------------------- 1 | /* p11-unwrapkey.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_UnwrapKey (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_OBJECT_HANDLE hUnwrappingKey, CK_BYTE_PTR pWrappedKey, 31 | CK_ULONG ulWrappedKeyLen, CK_ATTRIBUTE_PTR pTemplate, 32 | CK_ULONG ulAttributeCount, CK_OBJECT_HANDLE_PTR phKey) 33 | { 34 | (void) hSession; 35 | (void) pMechanism; 36 | (void) hUnwrappingKey; 37 | (void) pWrappedKey; 38 | (void) ulWrappedKeyLen; 39 | (void) pTemplate; 40 | (void) ulAttributeCount; 41 | (void) phKey; 42 | return CKR_FUNCTION_NOT_SUPPORTED; 43 | } 44 | -------------------------------------------------------------------------------- /src/p11-findobjectsfinal.c: -------------------------------------------------------------------------------- 1 | /* p11-findobjectsfinal.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #include "cryptoki.h" 28 | 29 | #include "locking.h" 30 | #include "slots.h" 31 | 32 | 33 | CK_RV CK_SPEC 34 | C_FindObjectsFinal (CK_SESSION_HANDLE hSession) 35 | { 36 | CK_RV err = CKR_OK; 37 | slot_iterator_t slot; 38 | session_iterator_t session; 39 | 40 | err = scute_global_lock (); 41 | if (err) 42 | return err; 43 | 44 | err = slots_lookup_session (hSession, &slot, &session); 45 | if (err) 46 | goto out; 47 | 48 | err = session_set_search_result (slot, session, NULL, 0); 49 | 50 | out: 51 | scute_global_unlock (); 52 | return err; 53 | } 54 | -------------------------------------------------------------------------------- /src/p11-finalize.c: -------------------------------------------------------------------------------- 1 | /* p11-finalize.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | #ifdef HAVE_W32_SYSTEM 25 | # include 26 | # include 27 | #endif 28 | 29 | #include "cryptoki.h" 30 | 31 | #include "slots.h" 32 | #include "agent.h" 33 | #include "locking.h" 34 | 35 | 36 | CK_RV CK_SPEC 37 | C_Finalize (CK_VOID_PTR pReserved) 38 | { 39 | /* This is one of the few functions which do not need to take the 40 | global lock. */ 41 | 42 | if (pReserved != NULL_PTR) 43 | return CKR_ARGUMENTS_BAD; 44 | 45 | scute_slots_finalize (); 46 | scute_agent_finalize (); 47 | scute_locking_finalize (); 48 | 49 | #ifdef HAVE_W32_SYSTEM 50 | WSACleanup (); 51 | #endif 52 | 53 | return CKR_OK; 54 | } 55 | -------------------------------------------------------------------------------- /src/p11-getinfo.c: -------------------------------------------------------------------------------- 1 | /* p11-getinfo.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "support.h" 28 | #include "settings.h" 29 | 30 | 31 | CK_RV CK_SPEC 32 | C_GetInfo (CK_INFO_PTR pInfo) 33 | { 34 | if (pInfo == NULL_PTR) 35 | return CKR_ARGUMENTS_BAD; 36 | 37 | pInfo->cryptokiVersion.major = CRYPTOKI_VERSION_MAJOR; 38 | pInfo->cryptokiVersion.minor = CRYPTOKI_VERSION_MINOR; 39 | scute_copy_string (pInfo->manufacturerID, MANUFACTURER_ID, 32); 40 | pInfo->flags = 0; 41 | scute_copy_string (pInfo->libraryDescription, LIBRARY_DESCRIPTION, 32); 42 | pInfo->libraryVersion.major = VERSION_MAJOR; 43 | pInfo->libraryVersion.minor = VERSION_MINOR; 44 | 45 | return CKR_OK; 46 | } 47 | -------------------------------------------------------------------------------- /tests/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am - Makefile in tests/ for scute. 2 | # Copyright (C) 2006 g10 Code GmbH 3 | # 4 | # This file is part of Scute. 5 | # 6 | # Scute is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Scute is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # SPDX-License-Identifier: LGPL-2.1-or-later 19 | 20 | ## Process this file with automake to produce Makefile.in 21 | 22 | noinst_HEADERS = t-support.h 23 | TESTS = t-link t-getfunctionlist t-initialize t-getinfo t-getslotlist \ 24 | t-getslotinfo t-gettokeninfo t-getmechanismlist t-getmechanisminfo \ 25 | t-opensession t-closeallsessions t-getsessioninfo \ 26 | t-findobjects t-getattribute t-auth t-generaterandom 27 | 28 | noinst_PROGRAMS = $(TESTS) 29 | 30 | EXTRA_DIST = clean-socketdir 31 | 32 | TESTS_ENVIRONMENT = GNUPGHOME=`/bin/pwd` GPG_AGENT_INFO= LC_ALL=C 33 | 34 | AM_CPPFLAGS = -I$(top_srcdir)/include -I$(top_srcdir)/src 35 | if HAVE_DARWIN_SYSTEM 36 | LDADD = ../src/libscute.la 37 | else 38 | LDADD = ../src/scute.la 39 | endif 40 | 41 | clean-local: 42 | $(TESTS_ENVIRONMENT) $(srcdir)/clean-socketdir 43 | -------------------------------------------------------------------------------- /src/p11-generatekeypair.c: -------------------------------------------------------------------------------- 1 | /* p11-generatekeypair.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | 28 | CK_RV CK_SPEC 29 | C_GenerateKeyPair (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 30 | CK_ATTRIBUTE_PTR pPublicKeyTemplate, 31 | CK_ULONG ulPublicKeyAttributeCount, 32 | CK_ATTRIBUTE_PTR pPrivateKeyTemplate, 33 | CK_ULONG ulPrivateKeyAttributeCount, 34 | CK_OBJECT_HANDLE_PTR phPublicKey, 35 | CK_OBJECT_HANDLE_PTR phPrivateKey) 36 | { 37 | (void) hSession; 38 | (void) pMechanism; 39 | (void) pPublicKeyTemplate; 40 | (void) ulPublicKeyAttributeCount; 41 | (void) pPrivateKeyTemplate; 42 | (void) ulPrivateKeyAttributeCount; 43 | (void) phPublicKey; 44 | (void) phPrivateKey; 45 | return CKR_FUNCTION_NOT_SUPPORTED; 46 | } 47 | -------------------------------------------------------------------------------- /src/p11-getmechanisminfo.c: -------------------------------------------------------------------------------- 1 | /* p11-getmechanisminfo.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | CK_RV CK_SPEC 32 | C_GetMechanismInfo (CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, 33 | CK_MECHANISM_INFO_PTR pInfo) 34 | { 35 | CK_RV err = CKR_OK; 36 | slot_iterator_t slot; 37 | mechanism_iterator_t mechanism; 38 | 39 | if (pInfo == NULL_PTR) 40 | return CKR_ARGUMENTS_BAD; 41 | 42 | err = scute_global_lock (); 43 | if (err) 44 | return err; 45 | 46 | err = slots_lookup (slotID, &slot); 47 | if (err) 48 | goto out; 49 | 50 | err = mechanisms_lookup (slot, &mechanism, type); 51 | if (err) 52 | goto out; 53 | 54 | *pInfo = *(mechanism_get_info (slot, mechanism)); 55 | 56 | out: 57 | scute_global_unlock (); 58 | return CKR_OK; 59 | } 60 | -------------------------------------------------------------------------------- /src/p11-generaterandom.c: -------------------------------------------------------------------------------- 1 | /* p11-generaterandom.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | #include "agent.h" 30 | #include "error-mapping.h" 31 | 32 | 33 | CK_RV CK_SPEC 34 | C_GenerateRandom (CK_SESSION_HANDLE hSession, 35 | CK_BYTE_PTR pRandomData, CK_ULONG ulRandomLen) 36 | { 37 | CK_RV err; 38 | slot_iterator_t slot; 39 | session_iterator_t session; 40 | 41 | if (pRandomData == NULL_PTR) 42 | return CKR_ARGUMENTS_BAD; 43 | 44 | err = scute_global_lock (); 45 | if (err) 46 | return err; 47 | 48 | err = slots_lookup_session (hSession, &slot, &session); 49 | if (!err) 50 | err = scute_gpg_err_to_ck (scute_agent_get_random (pRandomData, 51 | ulRandomLen)); 52 | 53 | scute_global_unlock (); 54 | return err; 55 | } 56 | -------------------------------------------------------------------------------- /tests/t-getinfo.c: -------------------------------------------------------------------------------- 1 | /* t-getinfo.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | int 27 | main (int argc, char *argv[]) 28 | { 29 | CK_RV err; 30 | CK_INFO info; 31 | 32 | (void) argc; 33 | (void) argv; 34 | 35 | init_cryptoki (); 36 | 37 | err = C_GetInfo (&info); 38 | fail_if_err (err); 39 | 40 | printf ("Cryptoki version: %i.%i\n", info.cryptokiVersion.major, 41 | info.cryptokiVersion.minor); 42 | if (info.cryptokiVersion.major != 2) 43 | fail ("Cryptoki major version is not 2"); 44 | if (info.cryptokiVersion.minor != 20) 45 | fail ("Cryptoki minor version is not 20"); 46 | 47 | printf ("Manufacturer ID: %.32s\n", info.manufacturerID); 48 | printf ("Flags: %#lx\n", info.flags); 49 | if (info.flags != 0) 50 | fail ("Flags is not 0"); 51 | 52 | printf ("Library description: %.32s\n", info.libraryDescription); 53 | printf ("Library version: %i.%i\n", info.libraryVersion.major, 54 | info.libraryVersion.minor); 55 | 56 | return 0; 57 | } 58 | -------------------------------------------------------------------------------- /src/p11-decryptinit.c: -------------------------------------------------------------------------------- 1 | /* p11-decryptinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006, 2019 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | #include "locking.h" 27 | #include "slots.h" 28 | 29 | 30 | /* Prepare a decryption operation. HSESSION is the session's handle, 31 | * MECHANISM points to an object describing the mechanism to be used, 32 | * and HKEY is a handle to the decryption key. After calling this 33 | * function either C_Decrypt or (C_DecryptUpdate, C_DecryptFinal) can 34 | * be used to actually decrypt the data. The preparation is valid 35 | * until a C_Decrypt or C_DecryptFinal. 36 | */ 37 | 38 | CK_RV CK_SPEC 39 | C_DecryptInit (CK_SESSION_HANDLE hsession, CK_MECHANISM *mechanism, 40 | CK_OBJECT_HANDLE hkey) 41 | { 42 | CK_RV rv; 43 | slot_iterator_t slot; 44 | session_iterator_t sid; 45 | 46 | if (!hsession || !mechanism || hkey == CK_INVALID_HANDLE) 47 | return CKR_ARGUMENTS_BAD; 48 | 49 | rv = scute_global_lock (); 50 | if (rv) 51 | return rv; 52 | 53 | rv = slots_lookup_session (hsession, &slot, &sid); 54 | if (!rv) 55 | rv = session_init_decrypt (slot, sid, mechanism, hkey); 56 | 57 | scute_global_unlock (); 58 | return rv; 59 | } 60 | -------------------------------------------------------------------------------- /src/p11-signinit.c: -------------------------------------------------------------------------------- 1 | /* p11-signinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | /* Prepare a signature operation. HSESSION is the session's handle. 31 | * PMECHANISM describes the mechanism to be used. HKEY describes the 32 | * key to be used. After calling this function either C_Sign or 33 | * (C_SignUpdate, C_SignFinal) can be used to actually sign the data. 34 | * The preparation is valid until C_Sign or C_SignFinal. */ 35 | CK_RV CK_SPEC 36 | C_SignInit (CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, 37 | CK_OBJECT_HANDLE hKey) 38 | { 39 | CK_RV err = CKR_OK; 40 | slot_iterator_t slot; 41 | session_iterator_t sid; 42 | 43 | if (pMechanism == NULL_PTR) 44 | return CKR_ARGUMENTS_BAD; 45 | 46 | if (hKey == CK_INVALID_HANDLE) 47 | return CKR_ARGUMENTS_BAD; 48 | 49 | err = scute_global_lock (); 50 | if (err) 51 | return err; 52 | 53 | err = slots_lookup_session (hSession, &slot, &sid); 54 | if (!err) 55 | err = session_set_signing_key (slot, sid, hKey, pMechanism->mechanism); 56 | 57 | scute_global_unlock (); 58 | return err; 59 | } 60 | -------------------------------------------------------------------------------- /src/gpgsm.h: -------------------------------------------------------------------------------- 1 | /* gpgsm.h - Interface for talking to gpgsm. 2 | Copyright (C) 2006 g10 Code GmbH 3 | 4 | This file is part of Scute. 5 | 6 | Scute is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | Scute is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Scute; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | In addition, as a special exception, g10 Code GmbH gives permission 21 | to link this library: with the Mozilla Foundation's code for 22 | Mozilla (or with modified versions of it that use the same license 23 | as the "Mozilla" code), and distribute the linked executables. You 24 | must obey the GNU General Public License in all respects for all of 25 | the code used other than "Mozilla". If you modify this file, you 26 | may extend this exception to your version of the file, but you are 27 | not obligated to do so. If you do not wish to do so, delete this 28 | exception statement from your version. */ 29 | 30 | #ifndef GPGSM_H 31 | #define GPGSM_H 1 32 | 33 | #include 34 | 35 | #include "cryptoki.h" 36 | 37 | #include "table.h" 38 | 39 | 40 | /* The callback type invoked for each certificate found in the 41 | search. */ 42 | typedef gpg_error_t (*cert_get_cb_t) (void *hook, 43 | CK_ATTRIBUTE_PTR attrp, 44 | CK_ULONG attr_countp); 45 | 46 | /* Create the attributes required for a new certificate object. */ 47 | gpg_error_t scute_gpgsm_get_cert (const char *grip, 48 | cert_get_cb_t cert_get_cb, void *hook); 49 | 50 | #endif /* GPGSM_H */ 51 | -------------------------------------------------------------------------------- /src/p11-opensession.c: -------------------------------------------------------------------------------- 1 | /* p11-opensession.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | CK_RV CK_SPEC 32 | C_OpenSession (CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, 33 | CK_NOTIFY Notify, CK_SESSION_HANDLE_PTR phSession) 34 | { 35 | CK_RV err = CKR_OK; 36 | slot_iterator_t slot; 37 | session_iterator_t session; 38 | 39 | if (!(flags & CKF_SERIAL_SESSION)) 40 | return CKR_SESSION_PARALLEL_NOT_SUPPORTED; 41 | 42 | /* We only support read-only operation for now. */ 43 | if (flags & CKF_RW_SESSION) 44 | return CKR_TOKEN_WRITE_PROTECTED; 45 | 46 | /* We ignore the notification callback data in pApplication and 47 | Notify. We never call back into the application. */ 48 | (void)pApplication; 49 | (void)Notify; 50 | 51 | err = scute_global_lock (); 52 | if (err) 53 | return err; 54 | 55 | err = slots_lookup (slotID, &slot); 56 | if (err) 57 | goto out; 58 | 59 | err = slot_create_session (slot, &session, flags & CKF_RW_SESSION); 60 | if (err) 61 | goto out; 62 | 63 | /* FIXME: Further initialisation comes here. */ 64 | 65 | *phSession = session; 66 | 67 | out: 68 | scute_global_unlock (); 69 | return err; 70 | } 71 | -------------------------------------------------------------------------------- /src/error-mapping.c: -------------------------------------------------------------------------------- 1 | /* error-mapping.c - Scute error mapping. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #include 28 | 29 | #include "cryptoki.h" 30 | #include "debug.h" 31 | 32 | #include "error-mapping.h" 33 | 34 | 35 | /* Map a system error code to a cryptoki return value. */ 36 | CK_RV 37 | scute_sys_to_ck (int err) 38 | { 39 | switch (err) 40 | { 41 | case 0: 42 | return CKR_OK; 43 | 44 | case ENOMEM: 45 | return CKR_HOST_MEMORY; 46 | 47 | default: 48 | /* CKR_GENERAL_ERROR is too strong. */ 49 | return CKR_FUNCTION_FAILED; 50 | } 51 | } 52 | 53 | 54 | /* Map a GnuPG error code to a cryptoki return value. */ 55 | CK_RV 56 | scute_gpg_err_to_ck (gpg_error_t err) 57 | { 58 | if (err) 59 | DEBUG (DBG_CRIT, "Error occurred: %s (%s)\n", gpg_strerror (err), 60 | gpg_strsource (err)); 61 | 62 | switch (gpg_err_code (err)) 63 | { 64 | case GPG_ERR_NO_ERROR: 65 | return CKR_OK; 66 | 67 | case GPG_ERR_NO_AGENT: 68 | return CKR_GENERAL_ERROR; 69 | 70 | case GPG_ERR_ENOMEM: 71 | return CKR_HOST_MEMORY; 72 | 73 | case GPG_ERR_BAD_PIN: 74 | return CKR_PIN_INCORRECT; 75 | 76 | case GPG_ERR_PIN_BLOCKED: 77 | return CKR_PIN_LOCKED; 78 | 79 | default: 80 | /* CKR_GENERAL_ERROR is too strong. */ 81 | return CKR_FUNCTION_FAILED; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/locking.h: -------------------------------------------------------------------------------- 1 | /* locking.h - Scute locking interface. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef LOCKING_H 22 | #define LOCKING_H 1 23 | 24 | #include "cryptoki.h" 25 | 26 | 27 | /* The lock type. */ 28 | typedef void *mutex_t; 29 | 30 | 31 | /* Initialize the locking support. ARGS is as provided to 32 | C_Initialize. */ 33 | CK_RV scute_locking_initialize (CK_C_INITIALIZE_ARGS_PTR args); 34 | 35 | /* Finalize the locking support. ARGS is as provided to 36 | C_Initialize. */ 37 | void scute_locking_finalize (void); 38 | 39 | 40 | /* Create a new mutex object. */ 41 | CK_RV scute_mutex_create (mutex_t *mutexp); 42 | 43 | /* Destroy an existing mutex object. */ 44 | CK_RV scute_mutex_destroy (mutex_t mutex); 45 | 46 | /* Lock a mutex object. */ 47 | CK_RV scute_mutex_lock (mutex_t mutex); 48 | 49 | /* Unlock a mutex object. */ 50 | CK_RV scute_mutex_unlock (mutex_t mutex); 51 | 52 | 53 | /* Scute is single-threaded, thus there is a single global lock taken 54 | at all entry points except for C_GetFunctionList, C_Initialize, 55 | C_Finalize and stubs. */ 56 | 57 | /* The global lock. */ 58 | extern mutex_t scute_lock; 59 | 60 | /* Take the global lock. */ 61 | static inline CK_RV 62 | scute_global_lock (void) 63 | { 64 | return scute_mutex_lock (scute_lock); 65 | } 66 | 67 | /* Release the global lock. */ 68 | static inline void 69 | scute_global_unlock (void) 70 | { 71 | (void) scute_mutex_unlock (scute_lock); 72 | } 73 | 74 | #endif /* !LOCKING_H */ 75 | -------------------------------------------------------------------------------- /src/p11-findobjects.c: -------------------------------------------------------------------------------- 1 | /* p11-findobjects.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | #include "cryptoki.h" 29 | 30 | #include "locking.h" 31 | #include "slots.h" 32 | 33 | #define MIN(a,b) ((a) < (b) ? (a) : (b)) 34 | 35 | 36 | CK_RV CK_SPEC 37 | C_FindObjects (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, 38 | CK_ULONG ulMaxObjectCount, CK_ULONG_PTR pulObjectCount) 39 | { 40 | CK_RV err = CKR_OK; 41 | CK_ULONG count; 42 | slot_iterator_t slot; 43 | session_iterator_t session; 44 | object_iterator_t *oids; 45 | int oids_len; 46 | 47 | if (!pulObjectCount) 48 | return CKR_ARGUMENTS_BAD; 49 | 50 | err = scute_global_lock (); 51 | if (err) 52 | return err; 53 | 54 | err = slots_lookup_session (hSession, &slot, &session); 55 | if (err) 56 | goto out; 57 | 58 | err = session_get_search_result (slot, session, &oids, &oids_len); 59 | assert (!err); 60 | 61 | count = MIN ((int) ulMaxObjectCount, oids_len); 62 | memcpy (phObject, oids, sizeof (CK_OBJECT_HANDLE) * count); 63 | 64 | oids_len = oids_len - count; 65 | memmove (oids, oids + count, sizeof (CK_OBJECT_HANDLE) * oids_len); 66 | err = session_set_search_result (slot, session, oids, oids_len); 67 | assert (!err); 68 | 69 | *pulObjectCount = count; 70 | 71 | out: 72 | scute_global_unlock (); 73 | return err; 74 | } 75 | -------------------------------------------------------------------------------- /src/p11-getslotinfo.c: -------------------------------------------------------------------------------- 1 | /* p11-getslotinfo.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | 28 | #include "cryptoki.h" 29 | 30 | #include "agent.h" 31 | #include "locking.h" 32 | #include "support.h" 33 | #include "settings.h" 34 | #include "slots.h" 35 | 36 | 37 | CK_RV CK_SPEC 38 | C_GetSlotInfo (CK_SLOT_ID slotID, CK_SLOT_INFO_PTR pInfo) 39 | { 40 | CK_RV err = CKR_OK; 41 | slot_iterator_t slot; 42 | const char *s; 43 | int minor; 44 | 45 | err = scute_global_lock (); 46 | if (err) 47 | return err; 48 | 49 | err = slots_lookup (slotID, &slot); 50 | if (err) 51 | goto out; 52 | 53 | /* FIXME: Query some of this from SCD. */ 54 | scute_copy_string (pInfo->slotDescription, SLOT_DESCRIPTION, 64); 55 | scute_copy_string (pInfo->manufacturerID, SLOT_MANUFACTURER_ID, 32); 56 | 57 | pInfo->flags = CKF_REMOVABLE_DEVICE | CKF_HW_SLOT; 58 | if (slot_token_present (slot)) 59 | pInfo->flags |= CKF_TOKEN_PRESENT; 60 | 61 | /* Use the gpg-agent version for the hardware version.. */ 62 | pInfo->hardwareVersion.major = get_gnupg_version (&minor); 63 | pInfo->hardwareVersion.minor = minor; 64 | 65 | /* Use Scute version as Firmware version. */ 66 | s = PACKAGE_VERSION; 67 | pInfo->firmwareVersion.major = atoi (s); 68 | s = strchr (s, '.'); 69 | pInfo->firmwareVersion.minor = s? atoi (s+1): 0; 70 | 71 | out: 72 | scute_global_unlock (); 73 | return err; 74 | } 75 | -------------------------------------------------------------------------------- /src/p11-getmechanismlist.c: -------------------------------------------------------------------------------- 1 | /* p11-getmechanismlist.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | CK_RV CK_SPEC 32 | C_GetMechanismList (CK_SLOT_ID slotID, CK_MECHANISM_TYPE_PTR pMechanismList, 33 | CK_ULONG_PTR pulCount) 34 | { 35 | CK_RV err = CKR_OK; 36 | CK_ULONG left; 37 | slot_iterator_t slot; 38 | mechanism_iterator_t mechanism; 39 | 40 | if (pulCount == NULL_PTR) 41 | return CKR_ARGUMENTS_BAD; 42 | 43 | err = scute_global_lock (); 44 | if (err) 45 | return err; 46 | 47 | err = slots_lookup (slotID, &slot); 48 | if (err) 49 | goto out; 50 | 51 | /* Leave LEFT positive for the whole search when only counting. */ 52 | left = pMechanismList ? *pulCount : 1; 53 | *pulCount = 0; 54 | err = mechanisms_iterate_first (slot, &mechanism); 55 | if (err) 56 | goto out; 57 | 58 | while (!mechanisms_iterate_last (slot, &mechanism) && left && !err) 59 | { 60 | (*pulCount)++; 61 | 62 | if (pMechanismList) 63 | { 64 | *(pMechanismList++) = mechanism_get_type (slot, mechanism); 65 | left--; 66 | } 67 | err = mechanisms_iterate_next (slot, &mechanism); 68 | } 69 | 70 | if (err) 71 | goto out; 72 | 73 | if (!mechanisms_iterate_last (slot, &mechanism) && !left) 74 | { 75 | err = CKR_BUFFER_TOO_SMALL; 76 | goto out; 77 | } 78 | 79 | out: 80 | scute_global_unlock (); 81 | return err; 82 | } 83 | -------------------------------------------------------------------------------- /src/settings.h: -------------------------------------------------------------------------------- 1 | /* settings.h - Settings for Scute's Cryptoki implementation. 2 | Copyright (C) 2006 g10 Code GmbH 3 | 4 | This file is part of Scute. 5 | 6 | Scute is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | Scute is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Scute; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | In addition, as a special exception, g10 Code GmbH gives permission 21 | to link this library: with the Mozilla Foundation's code for 22 | Mozilla (or with modified versions of it that use the same license 23 | as the "Mozilla" code), and distribute the linked executables. You 24 | must obey the GNU General Public License in all respects for all of 25 | the code used other than "Mozilla". If you modify this file, you 26 | may extend this exception to your version of the file, but you are 27 | not obligated to do so. If you do not wish to do so, delete this 28 | exception statement from your version. */ 29 | 30 | #ifndef SETTINGS_H 31 | #define SETTINGS_H 1 32 | 33 | /* Define this to 1 if threads are required for the implementation of 34 | the library. */ 35 | #define NEED_TO_CREATE_THREADS 0 36 | 37 | /* The manufacturer ID in UTF-8. Only up to 32 bytes are used. */ 38 | #define MANUFACTURER_ID "g10 Code GmbH" 39 | 40 | #define LIBRARY_DESCRIPTION "Cryptoki for GnuPG" 41 | 42 | /* The version number of this library. Defined by config.h. */ 43 | #if (! defined VERSION_MAJOR) || (! defined VERSION_MINOR) 44 | #error Define VERSION_MAJOR and VERSION_MINOR in config.h. 45 | #endif 46 | 47 | /* FIXME: The following should be queried from GnuPG, really. */ 48 | #define SLOT_DESCRIPTION "GnuPG Smart Card Daemon" 49 | #define SLOT_MANUFACTURER_ID "g10 Code GmbH" 50 | #define SLOT_HARDWARE_VERSION_MAJOR 0 51 | #define SLOT_HARDWARE_VERSION_MINOR 0 52 | 53 | #endif /* !SETTINGS_H */ 54 | -------------------------------------------------------------------------------- /README.GIT: -------------------------------------------------------------------------------- 1 | If you are building from GIT, run the script 2 | 3 | ./autogen.sh 4 | 5 | first, to make sure that you have all the necessary maintainer tools 6 | are installed and to build the actual configuration files. If you 7 | have just checked out from GIT, you should add the option "--force" to 8 | autogen.sh so that meta data is noticed by autom4te.cache. Then run 9 | 10 | ./configure --enable-maintainer-mode 11 | 12 | followed by the usual make. 13 | 14 | If autogen.sh complains about insufficient versions of the required 15 | tools, or the tools are not installed, you may use environment 16 | variables to override the default tool names: 17 | 18 | AUTOMAKE_SUFFIX is used as a suffix for all tools from the automake 19 | package. For example 20 | AUTOMAKE_SUFFIX="-1.14" ./autogen.sh 21 | uses "automake-1.14" and "aclocal-1.14. 22 | AUTOMAKE_PREFIX is used as a prefix for all tools from the automake 23 | page and may be combined with AUTOMAKE_SUFFIX. e.g.: 24 | AUTOMAKE_PREFIX=/usr/foo/bin ./autogen.sh 25 | uses "automake" and "aclocal" in the /usr/foo/bin 26 | directory. 27 | AUTOCONF_SUFFIX is used as a suffix for all tools from the automake 28 | package 29 | AUTOCONF_PREFIX is used as a prefix for all tools from the automake 30 | package 31 | GETTEXT_SUFFIX is used as a suffix for all tools from the gettext 32 | package 33 | GETTEXT_PREFIX is used as a prefix for all tools from the gettext 34 | package 35 | 36 | It is also possible to use the variable name AUTOMAKE, AUTOCONF, 37 | ACLOCAL, AUTOHEADER, GETTEXT and MSGMERGE to directly specify the name 38 | of the programs to run. It is however better to use the suffix and 39 | prefix forms as described above because that does not require 40 | knowledge about the actual tools used by autogen.sh. 41 | 42 | 43 | Please don't use autopoint, libtoolize or autoreconf unless you are 44 | the current maintainer and want to update the standard configuration 45 | files. All those files should be in GIT and only updated manually 46 | if the maintainer decides that newer versions are required. The 47 | maintainer should also make sure that the required version of automake 48 | et al. are properly indicated at the top of configure.ac and take care 49 | to copy the files and not merely use symlinks. 50 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am - Top level Makefile for scute. 2 | # Copyright (C) 2006 g10 Code GmbH 3 | # 4 | # This file is part of Scute. 5 | # 6 | # Scute is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Scute is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # SPDX-License-Identifier: LGPL-2.1-or-later 19 | 20 | ## Process this file with automake to produce Makefile.in 21 | 22 | AM_DISTCHECK_DVI_TARGET = pdf 23 | 24 | ACLOCAL_AMFLAGS = -I m4 25 | AUTOMAKE_OPTIONS = dist-bzip2 no-dist-gzip 26 | 27 | EXTRA_DIST = autogen.sh README.GIT VERSION build-aux/libtool-patch.sed 28 | 29 | if BUILD_TESTS 30 | tests = tests 31 | else 32 | tests = 33 | endif 34 | 35 | if BUILD_DOC 36 | doc = doc 37 | else 38 | doc = 39 | endif 40 | 41 | SUBDIRS = m4 src ${tests} ${doc} 42 | 43 | dist-hook: gen-ChangeLog 44 | 45 | distcheck-hook: 46 | set -e; ( \ 47 | pref="#+macro: scute_" ;\ 48 | reldate="$$(date -u +%Y-%m-%d)" ;\ 49 | echo "$${pref}ver $(PACKAGE_VERSION)" ;\ 50 | echo "$${pref}date $${reldate}" ;\ 51 | list='$(DIST_ARCHIVES)'; for i in $$list; do \ 52 | case "$$i" in *.tar.bz2) \ 53 | echo "$${pref}size $$(wc -c <$$i|awk '{print int($$1/1024)}')k" ;\ 54 | echo "$${pref}sha1 $$(sha1sum <$$i|cut -d' ' -f1)" ;\ 55 | echo "$${pref}sha2 $$(sha256sum <$$i|cut -d' ' -f1)" ;;\ 56 | esac;\ 57 | done ) | tee $(distdir).swdb 58 | 59 | .PHONY: gen-ChangeLog release sign-release 60 | 61 | gen_start_date = 2011-12-01T00:00:00 62 | gen-ChangeLog: 63 | if test -d $(top_srcdir)/.git; then \ 64 | (cd $(top_srcdir) && \ 65 | $(GITLOG_TO_CHANGELOG) --append-dot --tear-off \ 66 | --amend=build-aux/git-log-fix \ 67 | --since=$(gen_start_date) ) > $(distdir)/cl-t; \ 68 | cat $(top_srcdir)/build-aux/git-log-footer >> $(distdir)/cl-t;\ 69 | rm -f $(distdir)/ChangeLog; \ 70 | mv $(distdir)/cl-t $(distdir)/ChangeLog; \ 71 | fi 72 | -------------------------------------------------------------------------------- /src/p11-getsessioninfo.c: -------------------------------------------------------------------------------- 1 | /* p11-getsessioninfo.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #include "cryptoki.h" 28 | 29 | #include "locking.h" 30 | #include "slots.h" 31 | 32 | 33 | CK_RV CK_SPEC 34 | C_GetSessionInfo (CK_SESSION_HANDLE hSession, CK_SESSION_INFO_PTR pInfo) 35 | { 36 | CK_RV err = CKR_OK; 37 | slot_iterator_t slot; 38 | session_iterator_t session; 39 | bool rw; 40 | 41 | if (pInfo == NULL_PTR) 42 | return CKR_ARGUMENTS_BAD; 43 | 44 | err = scute_global_lock (); 45 | if (err) 46 | return err; 47 | 48 | err = slots_lookup_session (hSession, &slot, &session); 49 | if (err) 50 | goto out; 51 | 52 | /* We have to re-lookup the session handle, as it might just have 53 | become invalid. */ 54 | err = slots_lookup_session (hSession, &slot, &session); 55 | if (err) 56 | goto out; 57 | 58 | rw = session_get_rw (slot, session); 59 | switch (slot_get_login_status (slot)) 60 | { 61 | case SLOT_LOGIN_PUBLIC: 62 | pInfo->state = rw ? CKS_RW_PUBLIC_SESSION : CKS_RO_PUBLIC_SESSION; 63 | break; 64 | 65 | case SLOT_LOGIN_USER: 66 | pInfo->state = rw ? CKS_RW_USER_FUNCTIONS : CKS_RO_USER_FUNCTIONS; 67 | break; 68 | 69 | case SLOT_LOGIN_SO: 70 | assert (rw); 71 | pInfo->state = CKS_RW_SO_FUNCTIONS; 72 | break; 73 | 74 | default: 75 | assert (!"Unhandled slot login state."); 76 | break; 77 | } 78 | 79 | pInfo->slotID = slot_get_id (slot); 80 | pInfo->flags = CKF_SERIAL_SESSION 81 | | (rw ? CKF_RW_SESSION : 0); 82 | pInfo->ulDeviceError = 0; 83 | 84 | out: 85 | scute_global_unlock (); 86 | return err; 87 | } 88 | -------------------------------------------------------------------------------- /tests/t-getmechanismlist.c: -------------------------------------------------------------------------------- 1 | /* t-getmechanismlist.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | CK_RV err; 31 | CK_SLOT_ID_PTR slots; 32 | CK_ULONG slots_count; 33 | unsigned int i; 34 | 35 | (void) argc; 36 | (void) argv; 37 | 38 | init_cryptoki (); 39 | 40 | err = C_GetSlotList (true, NULL, &slots_count); 41 | fail_if_err (err); 42 | 43 | if (slots_count == 0) 44 | { 45 | printf ("Skipping test because no token is present.\n"); 46 | return 77; 47 | } 48 | 49 | printf ("Number of slots with tokens: %lu\n", slots_count); 50 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 51 | if (!slots) 52 | fail_if_err (CKR_HOST_MEMORY); 53 | 54 | err = C_GetSlotList (true, slots, &slots_count); 55 | fail_if_err (err); 56 | 57 | for (i = 0; i < slots_count; i++) 58 | { 59 | CK_MECHANISM_TYPE_PTR mechanisms; 60 | CK_ULONG mechanisms_count; 61 | unsigned int j; 62 | 63 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 64 | 65 | err = C_GetMechanismList (slots[i], NULL, &mechanisms_count); 66 | fail_if_err (err); 67 | 68 | printf (" Mechanisms: %lu\n", mechanisms_count); 69 | mechanisms = malloc (sizeof (CK_MECHANISM_TYPE) * mechanisms_count); 70 | if (!mechanisms) 71 | fail_if_err (CKR_HOST_MEMORY); 72 | 73 | err = C_GetMechanismList (slots[i], mechanisms, &mechanisms_count); 74 | fail_if_err (err); 75 | 76 | for (j = 0; j < mechanisms_count; j++) 77 | printf (" %2i. %s\n", j, mechanism_type_str (mechanisms[j])); 78 | 79 | free (mechanisms); 80 | } 81 | 82 | return 0; 83 | } 84 | -------------------------------------------------------------------------------- /tests/t-closeallsessions.c: -------------------------------------------------------------------------------- 1 | /* t-closeallsessions.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | CK_RV err; 31 | CK_SLOT_ID_PTR slots; 32 | CK_SESSION_HANDLE_PTR sessions; 33 | CK_ULONG slots_count; 34 | unsigned int i; 35 | 36 | (void) argc; 37 | (void) argv; 38 | 39 | init_cryptoki (); 40 | 41 | err = C_GetSlotList (true, NULL, &slots_count); 42 | fail_if_err (err); 43 | 44 | if (slots_count == 0) 45 | { 46 | printf ("Skipping test because no token is present.\n"); 47 | return 77; 48 | } 49 | 50 | printf ("Number of slots with tokens: %lu\n", slots_count); 51 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 52 | if (!slots) 53 | fail_if_err (CKR_HOST_MEMORY); 54 | 55 | sessions = malloc (sizeof (CK_SESSION_HANDLE) * slots_count * 2); 56 | if (!sessions) 57 | fail_if_err (CKR_HOST_MEMORY); 58 | 59 | err = C_GetSlotList (true, slots, &slots_count); 60 | fail_if_err (err); 61 | 62 | for (i = 0; i < slots_count; i++) 63 | { 64 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 65 | err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, 66 | &sessions[2 * i]); 67 | fail_if_err (err); 68 | 69 | printf (" Session ID 1: %lu\n", sessions[2 * i]); 70 | 71 | err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, 72 | &sessions[2 * i + 1]); 73 | fail_if_err (err); 74 | 75 | printf (" Session ID 2: %lu\n", sessions[2 * i + 1]); 76 | } 77 | 78 | for (i = 0; i < slots_count; i++) 79 | { 80 | err = C_CloseAllSessions (slots[i]); 81 | fail_if_err (err); 82 | } 83 | 84 | return 0; 85 | } 86 | -------------------------------------------------------------------------------- /src/p11-sign.c: -------------------------------------------------------------------------------- 1 | /* p11-sign.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | /* Sign the data (PDATA,ULDATALEN) using the information recorded in 32 | * the HSESSION by C_SignInit. PSIGNATURE is a buffer to receive the 33 | * signature. The length of that buffer must be stored in a variable 34 | * to which PULSIGNATURELEN points to; on success that length is 35 | * updated to the actual length of the signature in PULSIGNATURE. 36 | * 37 | * If the function returns CKR_BUFFER_TOO_SMALL no further C_SignInit 38 | * is required, instead the function can be called again with a larger 39 | * buffer. On a successful operation CKR_OK is returned and other 40 | * signatures may be created without a new C_SignInit. On all other 41 | * return codes a new C_SignInit is required. 42 | * 43 | * In contrast to the specs the return code CKR_ARGUMENTS_BAD may not 44 | * require a new C_SignInit because this can be considered a bug in 45 | * the caller's code. 46 | */ 47 | CK_RV CK_SPEC 48 | C_Sign (CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, 49 | CK_BYTE_PTR pSignature, CK_ULONG_PTR pulSignatureLen) 50 | { 51 | CK_RV err = CKR_OK; 52 | slot_iterator_t slot; 53 | session_iterator_t sid; 54 | 55 | if (pData == NULL_PTR || pulSignatureLen == NULL_PTR) 56 | return CKR_ARGUMENTS_BAD; 57 | 58 | err = scute_global_lock (); 59 | if (err) 60 | return err; 61 | 62 | err = slots_lookup_session (hSession, &slot, &sid); 63 | if (!err) 64 | err = session_sign (slot, sid, pData, ulDataLen, 65 | pSignature, pulSignatureLen); 66 | 67 | scute_global_unlock (); 68 | return err; 69 | } 70 | -------------------------------------------------------------------------------- /tests/t-getslotlist.c: -------------------------------------------------------------------------------- 1 | /* t-getslotlist.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #define PGM "t-getslotlist" 25 | #include "t-support.h" 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | int last_argc = -1; 31 | CK_RV err; 32 | int token = 0; 33 | CK_SLOT_ID_PTR slots; 34 | CK_ULONG slots_count; 35 | unsigned int i; 36 | 37 | if (argc) 38 | { argc--; argv++; } 39 | while (argc && last_argc != argc ) 40 | { 41 | last_argc = argc; 42 | if (!strcmp (*argv, "--")) 43 | { 44 | argc--; argv++; 45 | break; 46 | } 47 | else if (!strcmp (*argv, "--help")) 48 | { 49 | fputs ("usage: " PGM " [options]\n" 50 | "Options:\n" 51 | " --token Only present tokens\n", 52 | stdout); 53 | exit (0); 54 | } 55 | else if (!strcmp (*argv, "--token")) 56 | { 57 | argc--; argv++; 58 | token = 1; 59 | } 60 | else if (!strncmp (*argv, "--", 2)) 61 | { 62 | fprintf (stderr, "unknown option '%s'\n", *argv); 63 | exit (1); 64 | } 65 | } 66 | 67 | 68 | init_cryptoki (); 69 | 70 | err = C_GetSlotList (token, NULL, &slots_count); 71 | fail_if_err (err); 72 | 73 | printf ("Number of slots%s: %lu\n", token ? " (with tokens)" : "", 74 | slots_count); 75 | if (!slots_count) 76 | return 0; 77 | 78 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 79 | if (!slots) 80 | fail_if_err (CKR_HOST_MEMORY); 81 | 82 | err = C_GetSlotList (token, slots, &slots_count); 83 | fail_if_err (err); 84 | 85 | for (i = 0; i < slots_count; i++) 86 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 87 | 88 | return 0; 89 | } 90 | -------------------------------------------------------------------------------- /src/p11-getattributevalue.c: -------------------------------------------------------------------------------- 1 | /* p11-getattributevalue.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #include "cryptoki.h" 28 | 29 | #include "locking.h" 30 | #include "slots.h" 31 | 32 | 33 | CK_RV CK_SPEC 34 | C_GetAttributeValue (CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, 35 | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) 36 | { 37 | CK_RV err = CKR_OK; 38 | slot_iterator_t slot; 39 | session_iterator_t session; 40 | CK_ATTRIBUTE_PTR attr; 41 | CK_ULONG attr_count; 42 | 43 | if (pTemplate == NULL_PTR) 44 | return CKR_ARGUMENTS_BAD; 45 | 46 | err = scute_global_lock (); 47 | if (err) 48 | return err; 49 | 50 | err = slots_lookup_session (hSession, &slot, &session); 51 | if (err) 52 | goto out; 53 | 54 | err = slot_get_object (slot, hObject, &attr, &attr_count); 55 | if (err) 56 | goto out; 57 | 58 | while (ulCount--) 59 | { 60 | CK_ULONG i; 61 | 62 | for (i = 0; i < attr_count; i++) 63 | if (attr[i].type == pTemplate[ulCount].type) 64 | break; 65 | 66 | if (i == attr_count) 67 | { 68 | pTemplate[ulCount].ulValueLen = -1; 69 | err = CKR_ATTRIBUTE_TYPE_INVALID; 70 | } 71 | else 72 | { 73 | CK_ATTRIBUTE_PTR attribute = &attr[i]; 74 | 75 | pTemplate[ulCount].ulValueLen = attribute->ulValueLen; 76 | 77 | if (pTemplate[ulCount].pValue) 78 | { 79 | if (pTemplate[ulCount].ulValueLen >= attribute->ulValueLen) 80 | memcpy (pTemplate[ulCount].pValue, 81 | attribute->pValue, attribute->ulValueLen); 82 | else 83 | { 84 | pTemplate[ulCount].ulValueLen = -1; 85 | err = CKR_BUFFER_TOO_SMALL; 86 | } 87 | } 88 | } 89 | } 90 | 91 | out: 92 | scute_global_unlock (); 93 | return err; 94 | } 95 | -------------------------------------------------------------------------------- /src/locking.c: -------------------------------------------------------------------------------- 1 | /* locking.c - Locking support. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | #include 25 | 26 | 27 | #include "locking.h" 28 | 29 | /* Our copy of the initialization arguments. */ 30 | static CK_C_INITIALIZE_ARGS init_args; 31 | 32 | /* The global lock. */ 33 | mutex_t scute_lock; 34 | 35 | 36 | /* Initialize the locking support. ARGS is as provided to 37 | C_Initialize. */ 38 | CK_RV 39 | scute_locking_initialize (CK_C_INITIALIZE_ARGS_PTR args) 40 | { 41 | CK_RV err; 42 | 43 | if (args) 44 | init_args = *args; 45 | 46 | err = scute_mutex_create (&scute_lock); 47 | if (err) 48 | { 49 | if (args) 50 | memset (&init_args, 0, sizeof (init_args)); 51 | return err; 52 | } 53 | 54 | return CKR_OK; 55 | } 56 | 57 | 58 | /* Finalize the locking support. ARGS is as provided to 59 | C_Initialize. */ 60 | void 61 | scute_locking_finalize (void) 62 | { 63 | (void) scute_mutex_destroy (scute_lock); 64 | 65 | memset (&init_args, 0, sizeof (init_args)); 66 | } 67 | 68 | 69 | CK_RV 70 | scute_mutex_create (mutex_t *mutexp) 71 | { 72 | if (init_args.CreateMutex) 73 | return (*init_args.CreateMutex) (mutexp); 74 | 75 | return 0; 76 | } 77 | 78 | 79 | CK_RV 80 | scute_mutex_destroy (mutex_t mutex) 81 | { 82 | if (init_args.DestroyMutex) 83 | return (*init_args.DestroyMutex) (mutex); 84 | 85 | return 0; 86 | } 87 | 88 | 89 | CK_RV 90 | scute_mutex_lock (mutex_t mutex) 91 | { 92 | if (init_args.LockMutex) 93 | return (*init_args.LockMutex) (mutex); 94 | 95 | return 0; 96 | } 97 | 98 | 99 | CK_RV 100 | scute_mutex_unlock (mutex_t mutex) 101 | { 102 | if (init_args.LockMutex) 103 | return (*init_args.UnlockMutex) (mutex); 104 | 105 | return 0; 106 | } 107 | -------------------------------------------------------------------------------- /src/p11-decrypt.c: -------------------------------------------------------------------------------- 1 | /* p11-decrypt.c - Cryptoki implementation. 2 | * Copyright (C) 2006, 2019 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | #include "locking.h" 27 | #include "slots.h" 28 | 29 | /* Decrypt the data (ENCDATA,ENCDATALEN) using the information 30 | * recorded in HSESSION by C_DecryptInit. R_DATA is a buffer to 31 | * receive the decrypted data. The length of that buffer must be 32 | * stored in a variable to which R_DATALEN points to; on success that 33 | * length is updated to the actual length of the decrypted data at 34 | * R_DATA. In-place decryption is supported; that is ENCDATA and 35 | * R_DATA may be the same buffer. 36 | * 37 | * If the function returns CKR_BUFFER_TOO_SMALL no further 38 | * C_DecryptInit is required, instead the function can be called again 39 | * with a larger buffer. On all other return codes a new 40 | * C_DecryptInit is required. However, in contrast to the specs the 41 | * return code CKR_ARGUMENTS_BAD may not require a new C_DecryptInit 42 | * because this can be considered a bug in the caller's code. In case 43 | * the input cannot be decrypted because it has an inappropriate 44 | * length, then either CKR_ENCRYPTED_DATA_INVALID or 45 | * CKR_ENCRYPTED_DATA_LEN_RANGE may be returned. 46 | */ 47 | CK_RV CK_SPEC 48 | C_Decrypt (CK_SESSION_HANDLE hsession, 49 | CK_BYTE *encdata, CK_ULONG encdatalen, 50 | CK_BYTE *r_data, CK_ULONG *r_datalen) 51 | { 52 | CK_RV rv; 53 | slot_iterator_t slot; 54 | session_iterator_t sid; 55 | 56 | if (!hsession || !encdata || !r_datalen) 57 | return CKR_ARGUMENTS_BAD; 58 | 59 | rv = scute_global_lock (); 60 | if (rv) 61 | return rv; 62 | 63 | rv = slots_lookup_session (hsession, &slot, &sid); 64 | if (!rv) 65 | rv = session_decrypt (slot, sid, encdata, encdatalen, r_data, r_datalen); 66 | 67 | scute_global_unlock (); 68 | return rv; 69 | } 70 | -------------------------------------------------------------------------------- /src/libscute.vers: -------------------------------------------------------------------------------- 1 | # libscute.vers - List of symbols to export. 2 | # Copyright (C) 2002, 2004, 2005, 2006 g10 Code GmbH 3 | # 4 | # This file is part of Scute. 5 | # 6 | # Scute is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Scute is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # SPDX-License-Identifier: LGPL-2.1-or-later 19 | 20 | #---------------------------------------------------------- 21 | # Please remember to add new functions also to scute.def 22 | #---------------------------------------------------------- 23 | 24 | SCUTE_1.0 { 25 | global: 26 | C_CancelFunction; 27 | C_CloseAllSessions; 28 | C_CloseSession; 29 | C_CopyObject; 30 | C_CreateObject; 31 | C_Decrypt; 32 | C_DecryptDigestUpdate; 33 | C_DecryptFinal; 34 | C_DecryptInit; 35 | C_DecryptUpdate; 36 | C_DecryptVerifyUpdate; 37 | C_DeriveKey; 38 | C_DestroyObject; 39 | C_Digest; 40 | C_DigestEncryptUpdate; 41 | C_DigestFinal; 42 | C_DigestInit; 43 | C_DigestKey; 44 | C_DigestUpdate; 45 | C_Encrypt; 46 | C_EncryptFinal; 47 | C_EncryptInit; 48 | C_EncryptUpdate; 49 | C_Finalize; 50 | C_FindObjects; 51 | C_FindObjectsFinal; 52 | C_FindObjectsInit; 53 | C_GenerateKey; 54 | C_GenerateKeyPair; 55 | C_GenerateRandom; 56 | C_GetAttributeValue; 57 | C_GetFunctionList; 58 | C_GetFunctionStatus; 59 | C_GetInfo; 60 | C_GetMechanismInfo; 61 | C_GetMechanismList; 62 | C_GetObjectSize; 63 | C_GetOperationState; 64 | C_GetSessionInfo; 65 | C_GetSlotInfo; 66 | C_GetSlotList; 67 | C_GetTokenInfo; 68 | C_InitPIN; 69 | C_InitToken; 70 | C_Initialize; 71 | C_Login; 72 | C_Logout; 73 | C_OpenSession; 74 | C_SeedRandom; 75 | C_SetAttributeValue; 76 | C_SetOperationState; 77 | C_SetPIN; 78 | C_Sign; 79 | C_SignEncryptUpdate; 80 | C_SignFinal; 81 | C_SignInit; 82 | C_SignRecover; 83 | C_SignRecoverInit; 84 | C_SignUpdate; 85 | C_UnwrapKey; 86 | C_Verify; 87 | C_VerifyFinal; 88 | C_VerifyInit; 89 | C_VerifyRecover; 90 | C_VerifyRecoverInit; 91 | C_VerifyUpdate; 92 | C_WaitForSlotEvent; 93 | C_WrapKey; 94 | local: 95 | *; 96 | 97 | }; 98 | -------------------------------------------------------------------------------- /tests/t-generaterandom.c: -------------------------------------------------------------------------------- 1 | /* t-generaterandom.c - Regression test. 2 | * Copyright (C) 2016 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | CK_RV err; 31 | CK_SLOT_ID_PTR slots; 32 | CK_ULONG slots_count; 33 | unsigned int i; 34 | 35 | (void) argc; 36 | (void) argv; 37 | 38 | init_cryptoki (); 39 | 40 | err = C_GetSlotList (true, NULL, &slots_count); 41 | fail_if_err (err); 42 | 43 | if (slots_count == 0) 44 | { 45 | printf ("Skipping test because no token is present.\n"); 46 | return 77; 47 | } 48 | 49 | printf ("Number of slots with tokens: %lu\n", slots_count); 50 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 51 | if (!slots) 52 | fail_if_err (CKR_HOST_MEMORY); 53 | 54 | err = C_GetSlotList (true, slots, &slots_count); 55 | fail_if_err (err); 56 | 57 | for (i = 0; i < slots_count; i++) 58 | { 59 | CK_TOKEN_INFO info; 60 | 61 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 62 | 63 | err = C_GetTokenInfo (slots[i], &info); 64 | fail_if_err (err); 65 | 66 | if ((info.flags & CKF_RNG) > 0) 67 | { 68 | CK_SESSION_HANDLE session; 69 | unsigned char buffer[16]; 70 | unsigned int j; 71 | 72 | printf(" RNG available\n"); 73 | 74 | err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, 75 | &session); 76 | fail_if_err (err); 77 | 78 | printf (" Session ID: %lu\n", session); 79 | 80 | err = C_GenerateRandom (session, buffer, sizeof(buffer)); 81 | fail_if_err (err); 82 | 83 | printf (" Random bytes: 0x"); 84 | for (j = 0; j < sizeof(buffer); j++) 85 | printf ("%02x", buffer[j]); 86 | printf ("\n"); 87 | 88 | err = C_CloseSession (session); 89 | fail_if_err (err); 90 | } 91 | else 92 | printf (" No RNG available on token\n"); 93 | } 94 | 95 | return 0; 96 | } 97 | -------------------------------------------------------------------------------- /src/scute.def: -------------------------------------------------------------------------------- 1 | ; scute.def - List of symbols to export. 2 | ; Copyright (C) 2005, 2006 g10 Code GmbH 3 | ; 4 | ; This file is part of Scute. 5 | ; 6 | ; Scute is free software; you can redistribute it and/or modify it 7 | ; under the terms of the GNU Lesser General Public License as 8 | ; published by the Free Software Foundation; either version 2.1 of 9 | ; the License, or (at your option) any later version. 10 | ; 11 | ; Scute is distributed in the hope that it will be useful, but 12 | ; WITHOUT ANY WARRANTY; without even the implied warranty of 13 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | ; Lesser General Public License for more details. 15 | ; 16 | ; You should have received a copy of the GNU Lesser General Public 17 | ; License along with this program; if not, see . 18 | ; SPDX-License-Identifier: LGPL-2.1-or-later 19 | 20 | LIBRARY scute.dll 21 | 22 | EXPORTS 23 | C_CancelFunction @1 24 | C_CloseAllSessions @2 25 | C_CloseSession @3 26 | C_CopyObject @4 27 | C_CreateObject @5 28 | C_Decrypt @6 29 | C_DecryptDigestUpdate @7 30 | C_DecryptFinal @8 31 | C_DecryptInit @9 32 | C_DecryptUpdate @10 33 | C_DecryptVerifyUpdate @11 34 | C_DeriveKey @12 35 | C_DestroyObject @13 36 | C_Digest @14 37 | C_DigestEncryptUpdate @15 38 | C_DigestFinal @16 39 | C_DigestInit @17 40 | C_DigestKey @18 41 | C_DigestUpdate @19 42 | C_Encrypt @20 43 | C_EncryptFinal @21 44 | C_EncryptInit @22 45 | C_EncryptUpdate @23 46 | C_Finalize @24 47 | C_FindObjects @25 48 | C_FindObjectsFinal @26 49 | C_FindObjectsInit @27 50 | C_GenerateKey @28 51 | C_GenerateKeyPair @29 52 | C_GenerateRandom @30 53 | C_GetAttributeValue @31 54 | C_GetFunctionList @32 55 | C_GetFunctionStatus @33 56 | C_GetInfo @34 57 | C_GetMechanismInfo @35 58 | C_GetMechanismList @36 59 | C_GetObjectSize @37 60 | C_GetOperationState @38 61 | C_GetSessionInfo @39 62 | C_GetSlotInfo @40 63 | C_GetSlotList @41 64 | C_GetTokenInfo @42 65 | C_InitPIN @43 66 | C_InitToken @44 67 | C_Initialize @45 68 | C_Login @46 69 | C_Logout @47 70 | C_OpenSession @48 71 | C_SeedRandom @49 72 | C_SetAttributeValue @50 73 | C_SetOperationState @51 74 | C_SetPIN @52 75 | C_Sign @53 76 | C_SignEncryptUpdate @54 77 | C_SignFinal @55 78 | C_SignInit @56 79 | C_SignRecover @57 80 | C_SignRecoverInit @58 81 | C_SignUpdate @59 82 | C_UnwrapKey @60 83 | C_Verify @61 84 | C_VerifyFinal @62 85 | C_VerifyInit @63 86 | C_VerifyRecover @64 87 | C_VerifyRecoverInit @65 88 | C_VerifyUpdate @66 89 | C_WaitForSlotEvent @67 90 | C_WrapKey @68 91 | ; END 92 | -------------------------------------------------------------------------------- /src/p11-getslotlist.c: -------------------------------------------------------------------------------- 1 | /* p11-getslotlist.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "slots.h" 29 | 30 | 31 | /* Return the list of available slots. With TOKENPRESENT set only 32 | * slots with a present tokens are returned. If PSLOTLIST is NULL the 33 | * function only counts the number of slots and stores that number at 34 | * PULCOUNT. Further this also updates the internal state and thus 35 | * this needs to be called to check for new devices. If PSLOTLIST is 36 | * not NULL it must point to an array which receives the slot 37 | * information. PULCOUNT must point to a variable which initially 38 | * holds the number of allocated slot items and will be updated on 39 | * return to the stored number of slot items. 40 | */ 41 | CK_RV CK_SPEC 42 | C_GetSlotList (CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, 43 | CK_ULONG_PTR pulCount) 44 | { 45 | CK_RV err = CKR_OK; 46 | CK_ULONG left; 47 | slot_iterator_t slot; 48 | 49 | if (pulCount == NULL_PTR) 50 | return CKR_ARGUMENTS_BAD; 51 | 52 | err = scute_global_lock (); 53 | if (err) 54 | return err; 55 | 56 | if (pSlotList == NULL_PTR) 57 | { 58 | /* Firefox call GetSlotList even if there is active sessions. */ 59 | err = scute_slots_rescan_if_no_sessions (); 60 | if (err) 61 | goto out; 62 | } 63 | 64 | /* Leave LEFT positive for the whole search when only counting. */ 65 | left = pSlotList ? *pulCount : 1; 66 | *pulCount = 0; 67 | err = slots_iterate_first (&slot); 68 | if (err) 69 | goto out; 70 | 71 | while (!slots_iterate_last (&slot) && left && !err) 72 | { 73 | if (!tokenPresent || slot_token_present (slot)) 74 | { 75 | (*pulCount)++; 76 | 77 | if (pSlotList) 78 | { 79 | *(pSlotList++) = slot_get_id (slot); 80 | left--; 81 | } 82 | } 83 | err = slots_iterate_next (&slot); 84 | } 85 | 86 | if (err) 87 | goto out; 88 | 89 | if (!slots_iterate_last (&slot) && !left) 90 | { 91 | err = CKR_BUFFER_TOO_SMALL; 92 | goto out; 93 | } 94 | 95 | out: 96 | scute_global_unlock (); 97 | return err; 98 | } 99 | -------------------------------------------------------------------------------- /tests/t-opensession.c: -------------------------------------------------------------------------------- 1 | /* t-opensession.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #define PGM "t-opensession" 25 | #include "t-support.h" 26 | 27 | 28 | int 29 | main (int argc, char *argv[]) 30 | { 31 | int last_argc = -1; 32 | CK_RV err; 33 | CK_SLOT_ID_PTR slots; 34 | CK_SESSION_HANDLE_PTR sessions; 35 | CK_ULONG slots_count; 36 | unsigned int i; 37 | 38 | if (argc) 39 | { argc--; argv++; } 40 | while (argc && last_argc != argc ) 41 | { 42 | last_argc = argc; 43 | if (!strcmp (*argv, "--")) 44 | { 45 | argc--; argv++; 46 | break; 47 | } 48 | else if (!strcmp (*argv, "--help")) 49 | { 50 | fputs ("usage: " PGM " [options]\n" 51 | "No Options\n", 52 | stdout); 53 | exit (0); 54 | } 55 | else if (!strncmp (*argv, "--", 2)) 56 | { 57 | fprintf (stderr, "unknown option '%s'\n", *argv); 58 | exit (1); 59 | } 60 | } 61 | 62 | init_cryptoki (); 63 | 64 | err = C_GetSlotList (1, NULL, &slots_count); 65 | fail_if_err (err); 66 | 67 | if (slots_count == 0) 68 | { 69 | printf ("Skipping test because no token is present.\n"); 70 | return 77; 71 | } 72 | 73 | printf ("Number of slots with tokens: %lu\n", slots_count); 74 | 75 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 76 | if (!slots) 77 | fail_if_err (CKR_HOST_MEMORY); 78 | 79 | sessions = malloc (sizeof (CK_SESSION_HANDLE) * slots_count); 80 | if (!sessions) 81 | fail_if_err (CKR_HOST_MEMORY); 82 | 83 | err = C_GetSlotList (1, slots, &slots_count); 84 | fail_if_err (err); 85 | 86 | for (i = 0; i < slots_count; i++) 87 | { 88 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 89 | err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, 90 | &sessions[i]); 91 | fail_if_err (err); 92 | 93 | printf (" Session ID: %lu\n", sessions[i]); 94 | } 95 | 96 | for (i = 0; i < slots_count; i++) 97 | { 98 | err = C_CloseSession (sessions[i]); 99 | fail_if_err (err); 100 | } 101 | 102 | return 0; 103 | } 104 | -------------------------------------------------------------------------------- /src/table.h: -------------------------------------------------------------------------------- 1 | /* table.h - Iterative table interface. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #ifndef TABLE_H 22 | #define TABLE_H 1 23 | 24 | #include 25 | 26 | #include 27 | 28 | 29 | /* The indexed list type. */ 30 | struct scute_table; 31 | typedef struct scute_table *scute_table_t; 32 | 33 | 34 | /* TABLE interface. */ 35 | 36 | /* A table entry allocator function callback. Should return the new 37 | table entry in DATA_R. */ 38 | typedef gpg_error_t (*scute_table_alloc_cb_t) (void **data_r, void *hook); 39 | 40 | /* A table entry deallocator function callback. */ 41 | typedef void (*scute_table_dealloc_cb_t) (void *data); 42 | 43 | /* Allocate a new table and return it in TABLE_R. */ 44 | gpg_error_t scute_table_create (scute_table_t *table_r, 45 | scute_table_alloc_cb_t alloc, 46 | scute_table_dealloc_cb_t dealloc); 47 | 48 | /* Destroy the indexed list TABLE. This also calls the deallocator on 49 | all entries. */ 50 | void scute_table_destroy (scute_table_t table); 51 | 52 | /* Allocate a new table entry with a free index. Returns the index 53 | pointing to the new list entry in INDEX_R. This calls the 54 | allocator on the new entry before returning. Also returns the 55 | table entry in *DATA_R if this is not NULL. */ 56 | gpg_error_t scute_table_alloc (scute_table_t table, int *index_r, 57 | void **data_r, void *hook); 58 | 59 | /* Deallocate the list entry index. Afterwards, INDEX points to the 60 | following entry. This calls the deallocator on the entry before 61 | returning. */ 62 | void scute_table_dealloc (scute_table_t table, int *index); 63 | 64 | /* Return the index for the beginning of the list TABLE. */ 65 | int scute_table_first (scute_table_t table); 66 | 67 | /* Return the index following INDEX. If INDEX is the last element in 68 | the list, return 0. */ 69 | int scute_table_next (scute_table_t table, int index); 70 | 71 | /* Return true iff INDEX is the end-of-list marker. */ 72 | bool scute_table_last (scute_table_t table, int index); 73 | 74 | /* Return the user data associated with INDEX. Return NULL if INDEX is 75 | the end-of-list marker. */ 76 | void *scute_table_data (scute_table_t table, int index); 77 | 78 | /* Return the number of entries in the table TABLE. */ 79 | int scute_table_used (scute_table_t table); 80 | 81 | #endif /* !TABLE_H */ 82 | -------------------------------------------------------------------------------- /src/agent.h: -------------------------------------------------------------------------------- 1 | /* agent.h - Interface for talking to gpg-agent. 2 | Copyright (C) 2006, 2007 g10 Code GmbH 3 | 4 | This file is part of Scute. 5 | 6 | Scute is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | Scute is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Scute; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | In addition, as a special exception, g10 Code GmbH gives permission 21 | to link this library: with the Mozilla Foundation's code for 22 | Mozilla (or with modified versions of it that use the same license 23 | as the "Mozilla" code), and distribute the linked executables. You 24 | must obey the GNU General Public License in all respects for all of 25 | the code used other than "Mozilla". If you modify this file, you 26 | may extend this exception to your version of the file, but you are 27 | not obligated to do so. If you do not wish to do so, delete this 28 | exception statement from your version. */ 29 | 30 | #ifndef AGENT_H 31 | #define AGENT_H 1 32 | 33 | #include 34 | #include 35 | 36 | #include "cert.h" 37 | 38 | struct keyinfo 39 | { 40 | struct keyinfo *next; 41 | char grip[41]; 42 | char *serialno; 43 | }; 44 | 45 | /* Try to connect to the agent via socket. Handle the server's 46 | initial greeting. */ 47 | gpg_error_t scute_agent_initialize (void); 48 | 49 | /* Tear down the agent connection and release all associated 50 | resources. */ 51 | void scute_agent_finalize (void); 52 | 53 | gpg_error_t scute_agent_keyinfo_list (struct keyinfo **l_p); 54 | void scute_agent_free_keyinfo (struct keyinfo *l); 55 | 56 | /* Sign the data DATA of length LEN with the key HEXGRIP and return 57 | * the signature in SIG_RESULT and SIG_LEN. */ 58 | gpg_error_t scute_agent_sign (const char *hexgrip, CK_MECHANISM_TYPE mechtype, 59 | unsigned char *data, int len, 60 | unsigned char *sig_result, unsigned int *sig_len); 61 | 62 | /* Decrypt data. */ 63 | gpg_error_t scute_agent_decrypt (const char *hexgrip, 64 | unsigned char *encdata, int encdatalen, 65 | unsigned char *r_plaindata, 66 | unsigned int *r_plaindatalen); 67 | 68 | /* Determine if FPR is trusted. */ 69 | gpg_error_t scute_agent_is_trusted (const char *fpr, bool *is_trusted); 70 | 71 | /* Get random bytes from the card. */ 72 | gpg_error_t scute_agent_get_random (unsigned char *data, size_t len); 73 | 74 | gpg_error_t scute_agent_keyinfo_list (struct keyinfo **keyinfo_p); 75 | 76 | gpg_error_t scute_agent_serialno (void); 77 | 78 | #endif /* AGENT_H */ 79 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- 1 | Noteworthy changes in version 1.7.1 (unreleased) 2 | ------------------------------------------------ 3 | 4 | * Support ECC signatures. 5 | 6 | * Support multiple cards. 7 | 8 | 9 | 10 | Noteworthy changes in version 1.7.0 (2021-01-07) 11 | ------------------------------------------------ 12 | 13 | * Support pre-formatted PSS signatures to work with OpenVPN. 14 | 15 | * Support for a global config file. 16 | 17 | * A minimal man page is provided. 18 | 19 | * Windows build problems have been fixed. 20 | 21 | Release-info: https://dev.gnupg.org/T5224 22 | 23 | 24 | Noteworthy changes in version 1.6.0 (2019-09-11) 25 | ------------------------------------------------ 26 | 27 | * Support for PIV cards. 28 | 29 | * Speedup by letting GPGSM select missing keys. 30 | 31 | * License change to LGPL-2.1-or-later. 32 | (See commit 60a071e3b7b2885ce994667a9186173772f3a647). 33 | 34 | * Requires at a minimum the current stable version of GnuPG (2.2.0) 35 | but advanced PIV card support needs the current GnuPG development 36 | version. 37 | 38 | 39 | Noteworthy changes in version 1.5.0 (2017-07-14) 40 | ------------------------------------------------ 41 | 42 | * Support for TLS 1.2 client authentication and S/MIME signing. 43 | 44 | * Support for 4096 bit keys. 45 | 46 | * Support for GnuPG 2.1. 47 | 48 | * C_GenerateRandom is implemented. 49 | 50 | 51 | Noteworthy changes in version 1.4.0 (2010-04-21) 52 | ------------------------------------------------ 53 | 54 | * Update to libassuan 2.0.0 interface. 55 | 56 | 57 | Noteworthy changes in version 1.3.0 (2009-06-19) 58 | ------------------------------------------------ 59 | 60 | * Scute can read certificates directly from the OpenPGP 2.0 cards. 61 | 62 | * Support for 2048 bit keys. 63 | 64 | 65 | Noteworthy changes in version 1.2.0 (2008-09-02) 66 | ------------------------------------------------ 67 | 68 | * Ported to Windows 32. 69 | 70 | * GPG Agent can now be launched on demand. 71 | 72 | Noteworthy changes in version 1.1.0 (2007-05-03) 73 | ------------------------------------------------ 74 | 75 | * Scute now comes with a manual. 76 | 77 | * Code licensed from RSA Security Inc. has been removed due to 78 | licensing issues ("advertisment clause"). 79 | 80 | * A memory leak has been fixed. Note that you need libassuan 1.0.1 81 | to fix another memory leak. 82 | 83 | * Scute now supports certificates larger than the kernel pipe buffer 84 | with GPGSM versions later than 2.0.0 (exclusive). 85 | 86 | * Scute now sets the CKA_TRUSTED attribute to something useful. 87 | 88 | 89 | Noteworthy changes in version 1.0.0 (2006-11-11) 90 | ------------------------------------------------ 91 | 92 | * Initial release. 93 | 94 | 95 | Copyright 2006, 2009, 2010 g10 Code GmbH 96 | 97 | This file is free software; as a special exception the author gives 98 | unlimited permission to copy and/or distribute it, with or without 99 | modifications, as long as this notice is preserved. 100 | 101 | This file is distributed in the hope that it will be useful, but 102 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 103 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 104 | -------------------------------------------------------------------------------- /src/support.h: -------------------------------------------------------------------------------- 1 | /* support.h - Cryptoki implementation support functions. 2 | Copyright (C) 2006 g10 Code GmbH 3 | 4 | This file is part of Scute. 5 | 6 | Scute is free software; you can redistribute it and/or modify it 7 | under the terms of the GNU General Public License as published by 8 | the Free Software Foundation; either version 2 of the License, or 9 | (at your option) any later version. 10 | 11 | Scute is distributed in the hope that it will be useful, but 12 | WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with Scute; if not, write to the Free Software Foundation, 18 | Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 | 20 | In addition, as a special exception, g10 Code GmbH gives permission 21 | to link this library: with the Mozilla Foundation's code for 22 | Mozilla (or with modified versions of it that use the same license 23 | as the "Mozilla" code), and distribute the linked executables. You 24 | must obey the GNU General Public License in all respects for all of 25 | the code used other than "Mozilla". If you modify this file, you 26 | may extend this exception to your version of the file, but you are 27 | not obligated to do so. If you do not wish to do so, delete this 28 | exception statement from your version. */ 29 | 30 | #ifndef SUPPORT_H 31 | #define SUPPORT_H 1 32 | 33 | #include 34 | 35 | #define spacep(p) (*(p) == ' ' || *(p) == '\t') 36 | #define digitp(p) (*(p) >= '0' && *(p) <= '9') 37 | #define hexdigitp(a) (digitp (a) \ 38 | || (*(a) >= 'A' && *(a) <= 'F') \ 39 | || (*(a) >= 'a' && *(a) <= 'f')) 40 | #define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \ 41 | *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10)) 42 | #define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1)) 43 | 44 | #define DIM(x) (sizeof (x) / sizeof (x[0])) 45 | 46 | /* Copy a string into its location, with blank character padding. */ 47 | static inline void 48 | scute_copy_string (char *dest, const char *src, int max_len) 49 | { 50 | int i; 51 | for (i = 0; (i < max_len) && (*src != '\0'); i++) 52 | *(dest++) = *(src++); 53 | while (i++ < max_len) 54 | *(dest++) = ' '; 55 | } 56 | 57 | /* Use gpg-errors printf functions for better portability. We also 58 | replace the standard snprintf with our implementation due to a bug 59 | in some mingw32 versions related to the 'l' format modifier. */ 60 | #define asprintf gpgrt_asprintf 61 | #define vasprintf gpgrt_vasprintf 62 | #define snprintf gpgrt_snprintf 63 | 64 | /*-- Simple replacement functions. */ 65 | #ifndef HAVE_TTYNAME 66 | /* Systems without ttyname (W32) will merely return NULL. */ 67 | static inline char * 68 | ttyname (int fd) 69 | { 70 | (void)fd; 71 | return NULL; 72 | } 73 | #endif /* !HAVE_TTYNAME */ 74 | 75 | 76 | gpg_error_t read_first_line (const char *command, char *buffer, size_t bufsize); 77 | const char *get_gpgconf_path (void); 78 | int get_gnupg_version (int *minor); 79 | int is_gnupg_older_than (int major, int minor, int micro); 80 | const char *get_gpgsm_path (void); 81 | 82 | 83 | 84 | #endif /* !SUPPORT_H */ 85 | -------------------------------------------------------------------------------- /src/debug.c: -------------------------------------------------------------------------------- 1 | /* debug.c - Cryptoki implementation. 2 | * Copyright (C) 2008 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include 30 | #include 31 | #include 32 | 33 | #include "debug.h" 34 | 35 | 36 | FILE *_scute_debug_stream; 37 | 38 | 39 | 40 | #ifdef HAVE_W32_SYSTEM 41 | #define PATHSEP_C ';' 42 | #else 43 | #define PATHSEP_C ':' 44 | #endif 45 | 46 | 47 | /* Remove leading and trailing white spaces. */ 48 | static char * 49 | trim_spaces (char *str) 50 | { 51 | char *string, *p, *mark; 52 | 53 | string = str; 54 | /* Find first non space character. */ 55 | for (p = string; *p && isspace (*(unsigned char *) p); p++) 56 | ; 57 | /* Move characters. */ 58 | for (mark = NULL; (*string = *p); string++, p++) 59 | if (isspace (*(unsigned char *) p)) 60 | { 61 | if (!mark) 62 | mark = string; 63 | } 64 | else 65 | mark = NULL; 66 | if (mark) 67 | *mark = '\0'; /* Remove trailing spaces. */ 68 | 69 | return str; 70 | } 71 | 72 | #include 73 | 74 | void 75 | _scute_debug_init (void) 76 | { 77 | static int initialized; 78 | 79 | if (!initialized) 80 | { 81 | char *e; 82 | const char *s1, *s2; 83 | FILE *stream; 84 | 85 | e = getenv ("SCUTE_DEBUG"); 86 | 87 | initialized = 1; 88 | 89 | stream = stderr; 90 | if (e) 91 | { 92 | _scute_opt.debug_flags = atoi (e); 93 | s1 = strchr (e, PATHSEP_C); 94 | if (s1) 95 | { 96 | #ifndef HAVE_W32_SYSTEM 97 | if (getuid () == geteuid ()) 98 | { 99 | #endif 100 | char *p; 101 | FILE *fp; 102 | 103 | s1++; 104 | if (!(s2 = strchr (s1, PATHSEP_C))) 105 | s2 = s1 + strlen (s1); 106 | p = malloc (s2 - s1 + 1); 107 | if (p) 108 | { 109 | memcpy (p, s1, s2 - s1); 110 | p[s2-s1] = 0; 111 | trim_spaces (p); 112 | fp = fopen (p,"a"); 113 | if (fp) 114 | { 115 | setvbuf (fp, NULL, _IOLBF, 0); 116 | stream = fp; 117 | } 118 | free (p); 119 | } 120 | #ifndef HAVE_W32_SYSTEM 121 | } 122 | #endif 123 | } 124 | } 125 | 126 | if (_scute_opt.debug_flags > 0) 127 | fprintf (stream, "scute debug init: flags=0x%x\n", _scute_opt.debug_flags); 128 | 129 | assuan_set_assuan_log_prefix ("scute-assuan"); 130 | _scute_debug_stream = stream; 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /src/p11-initialize.c: -------------------------------------------------------------------------------- 1 | /* p11-initialize.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | 27 | #ifdef HAVE_W32_SYSTEM 28 | #define __USE_W32_SOCKETS 1 29 | # include 30 | # include 31 | #endif 32 | 33 | #include 34 | #include 35 | 36 | #include "cryptoki.h" 37 | 38 | #include "settings.h" 39 | #include "locking.h" 40 | #include "agent.h" 41 | #include "error-mapping.h" 42 | #include "slots.h" 43 | #include "debug.h" 44 | #include "options.h" 45 | 46 | 47 | CK_RV CK_SPEC 48 | C_Initialize (CK_VOID_PTR pInitArgs) 49 | { 50 | CK_RV err; 51 | 52 | #ifdef HAVE_W32_SYSTEM 53 | WSADATA wsadat; 54 | 55 | WSAStartup (0x202, &wsadat); 56 | #endif 57 | 58 | /* This is one of the few functions which do not need to take the 59 | global lock. */ 60 | 61 | assuan_set_gpg_err_source (GPG_ERR_SOURCE_ANY); 62 | 63 | _scute_debug_init (); 64 | _scute_read_conf (); 65 | 66 | /* Check the threading configuration. */ 67 | if (pInitArgs != NULL_PTR) 68 | { 69 | CK_C_INITIALIZE_ARGS_PTR args = pInitArgs; 70 | bool callbacks; 71 | 72 | if (args->pReserved != NULL_PTR) 73 | return CKR_ARGUMENTS_BAD; 74 | 75 | if (NEED_TO_CREATE_THREADS 76 | && (args->flags & CKF_LIBRARY_CANT_CREATE_OS_THREADS)) 77 | return CKR_NEED_TO_CREATE_THREADS; 78 | 79 | /* Either all pointers are provided, or none are. */ 80 | if (args->CreateMutex == NULL_PTR) 81 | { 82 | if (args->DestroyMutex != NULL_PTR || args->LockMutex != NULL_PTR 83 | || args->UnlockMutex != NULL_PTR) 84 | return CKR_ARGUMENTS_BAD; 85 | 86 | callbacks = false; 87 | } 88 | else 89 | { 90 | if (args->DestroyMutex == NULL_PTR || args->LockMutex == NULL_PTR 91 | || args->UnlockMutex == NULL_PTR) 92 | return CKR_ARGUMENTS_BAD; 93 | 94 | callbacks = true; 95 | } 96 | 97 | /* FIXME: At this point, we do not support using the native 98 | thread package. */ 99 | if (!callbacks && (args->flags & CKF_OS_LOCKING_OK)) 100 | if (!_scute_opt.assume_single_threaded) 101 | return CKR_CANT_LOCK; 102 | } 103 | 104 | err = scute_locking_initialize (pInitArgs); 105 | if (err) 106 | return err; 107 | 108 | err = scute_agent_initialize (); 109 | if (err) 110 | { 111 | scute_locking_finalize (); 112 | return scute_gpg_err_to_ck (err); 113 | } 114 | 115 | return err; 116 | } 117 | -------------------------------------------------------------------------------- /tests/t-link.c: -------------------------------------------------------------------------------- 1 | /* t-link.c - Simple linking regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | 23 | #include "t-support.h" 24 | 25 | #define DO_ONE(fnc) printf (#fnc ": %p\n", fnc) 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | (void) argc; 31 | (void) argv; 32 | 33 | /* We don't do anything useful. We just print a list of function 34 | pointers to avoid elimination of dead code. */ 35 | DO_ONE (C_CancelFunction); 36 | DO_ONE (C_CloseAllSessions); 37 | DO_ONE (C_CloseSession); 38 | DO_ONE (C_CopyObject); 39 | DO_ONE (C_CreateObject); 40 | DO_ONE (C_Decrypt); 41 | DO_ONE (C_DecryptDigestUpdate); 42 | DO_ONE (C_DecryptFinal); 43 | DO_ONE (C_DecryptInit); 44 | DO_ONE (C_DecryptUpdate); 45 | DO_ONE (C_DecryptVerifyUpdate); 46 | DO_ONE (C_DeriveKey); 47 | DO_ONE (C_DestroyObject); 48 | DO_ONE (C_Digest); 49 | DO_ONE (C_DigestEncryptUpdate); 50 | DO_ONE (C_DigestFinal); 51 | DO_ONE (C_DigestInit); 52 | DO_ONE (C_DigestKey); 53 | DO_ONE (C_DigestUpdate); 54 | DO_ONE (C_Encrypt); 55 | DO_ONE (C_EncryptFinal); 56 | DO_ONE (C_EncryptInit); 57 | DO_ONE (C_EncryptUpdate); 58 | DO_ONE (C_Finalize); 59 | DO_ONE (C_FindObjects); 60 | DO_ONE (C_FindObjectsFinal); 61 | DO_ONE (C_FindObjectsInit); 62 | DO_ONE (C_GenerateKey); 63 | DO_ONE (C_GenerateKeyPair); 64 | DO_ONE (C_GenerateRandom); 65 | DO_ONE (C_GetAttributeValue); 66 | DO_ONE (C_GetFunctionList); 67 | DO_ONE (C_GetFunctionStatus); 68 | DO_ONE (C_GetInfo); 69 | DO_ONE (C_GetMechanismInfo); 70 | DO_ONE (C_GetMechanismList); 71 | DO_ONE (C_GetObjectSize); 72 | DO_ONE (C_GetOperationState); 73 | DO_ONE (C_GetSessionInfo); 74 | DO_ONE (C_GetSlotInfo); 75 | DO_ONE (C_GetSlotList); 76 | DO_ONE (C_GetTokenInfo); 77 | DO_ONE (C_InitPIN); 78 | DO_ONE (C_InitToken); 79 | DO_ONE (C_Initialize); 80 | DO_ONE (C_Login); 81 | DO_ONE (C_Logout); 82 | DO_ONE (C_OpenSession); 83 | DO_ONE (C_SeedRandom); 84 | DO_ONE (C_SetAttributeValue); 85 | DO_ONE (C_SetOperationState); 86 | DO_ONE (C_SetPIN); 87 | DO_ONE (C_Sign); 88 | DO_ONE (C_SignEncryptUpdate); 89 | DO_ONE (C_SignFinal); 90 | DO_ONE (C_SignInit); 91 | DO_ONE (C_SignRecover); 92 | DO_ONE (C_SignRecoverInit); 93 | DO_ONE (C_SignUpdate); 94 | DO_ONE (C_UnwrapKey); 95 | DO_ONE (C_Verify); 96 | DO_ONE (C_VerifyFinal); 97 | DO_ONE (C_VerifyInit); 98 | DO_ONE (C_VerifyRecover); 99 | DO_ONE (C_VerifyRecoverInit); 100 | DO_ONE (C_VerifyUpdate); 101 | DO_ONE (C_WaitForSlotEvent); 102 | DO_ONE (C_WrapKey); 103 | 104 | return 0; 105 | } 106 | -------------------------------------------------------------------------------- /doc/Makefile.am: -------------------------------------------------------------------------------- 1 | # Makefile.am - Doc directory Makefile for scute. 2 | # Copyright (C) 2006, 2007 g10 Code GmbH 3 | # 4 | # This file is part of Scute. 5 | # 6 | # Scute is free software; you can redistribute it and/or modify it 7 | # under the terms of the GNU Lesser General Public License as 8 | # published by the Free Software Foundation; either version 2.1 of 9 | # the License, or (at your option) any later version. 10 | # 11 | # Scute is distributed in the hope that it will be useful, but 12 | # WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | # Lesser General Public License for more details. 15 | # 16 | # You should have received a copy of the GNU Lesser General Public 17 | # License along with this program; if not, see . 18 | # SPDX-License-Identifier: LGPL-2.1-or-later 19 | 20 | ## Process this file with automake to produce Makefile.in 21 | 22 | infoimagedir = $(infodir)/images 23 | 24 | images = images/firefox-cm.png images/firefox-cm-view-detail.png \ 25 | images/firefox-cm-view.png images/firefox-dm-load-after.png \ 26 | images/firefox-dm-load-before.png images/firefox-dm-load.png \ 27 | images/firefox-dm-token-present.png images/firefox-pref.png \ 28 | images/firefox-pref-view.png images/firefox-bad-pin.png \ 29 | images/thunderbird-account-settings.png \ 30 | images/thunderbird-smime-button.png \ 31 | images/libreoffice-certificate-selection.png \ 32 | images/libreoffice-digital-signatures.png \ 33 | images/libreoffice-pdf-signature.png 34 | 35 | dist_infoimage_DATA = $(images) 36 | 37 | DISTCLEANFILES = scute.tmp yat2m-stamp.tmp yat2m-stamp $(myman_pages) 38 | 39 | 40 | info_TEXINFOS = scute.texi 41 | scute_TEXINFOS = lesser.texi 42 | 43 | YAT2M = yat2m 44 | YAT2M_OPTIONS = -I $(srcdir) \ 45 | --release "Scute @PACKAGE_VERSION@" --source "Scute" 46 | 47 | myman_sources = scute.texi 48 | myman_pages = scute.7 49 | 50 | man_MANS = $(myman_pages) 51 | 52 | 53 | yat2m-stamp: $(myman_sources) $(srcdir)/version.texi 54 | @rm -f yat2m-stamp.tmp 55 | @touch yat2m-stamp.tmp 56 | for file in $(myman_sources) ; do \ 57 | $(YAT2M) $(YAT2M_OPTIONS) --store \ 58 | `test -f '$$file' || echo '$(srcdir)/'`$$file ; done 59 | @mv -f yat2m-stamp.tmp $@ 60 | 61 | $(myman_pages) : yat2m-stamp 62 | @if test -f $@; then :; else \ 63 | trap 'rm -rf yat2m-stamp yat2m-lock' 1 2 13 15; \ 64 | if mkdir yat2m-lock 2>/dev/null; then \ 65 | rm -f yat2m-stamp; \ 66 | $(MAKE) $(AM_MAKEFLAGS) yat2m-stamp; \ 67 | rmdir yat2m-lock; \ 68 | else \ 69 | while test -d yat2m-lock; do sleep 1; done; \ 70 | test -f yat2m-stamp; exit $$?; \ 71 | fi; \ 72 | fi 73 | 74 | 75 | # Make sure that scute.texi is touched if any other source file has 76 | # been modified. This is required so that the version.texi magic 77 | # updates the release date. 78 | scute.texi : $(scute_TEXINFOS) $(images) 79 | touch $(srcdir)/scute.texi 80 | 81 | 82 | online: scute.html scute.pdf 83 | set -e; \ 84 | echo "Uploading current manuals to www.gnupg.org ..."; \ 85 | for f in $(images); do \ 86 | cp $(srcdir)/$$f scute.html/; \ 87 | done ; \ 88 | user=werner ; webhost="ftp.gnupg.org"; \ 89 | rsync -v scute.pdf \ 90 | $${user}@$${webhost}:webspace/manuals/ ; \ 91 | cd scute.html ; \ 92 | rsync -vr -C . \ 93 | $${user}@$${webhost}:webspace/manuals/scute/ 94 | -------------------------------------------------------------------------------- /tests/t-getsessioninfo.c: -------------------------------------------------------------------------------- 1 | /* t-getsessioninfo.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | CK_RV err; 31 | CK_SLOT_ID_PTR slots; 32 | CK_SESSION_HANDLE_PTR sessions; 33 | CK_ULONG slots_count; 34 | unsigned int i; 35 | 36 | (void) argc; 37 | (void) argv; 38 | 39 | init_cryptoki (); 40 | 41 | err = C_GetSlotList (true, NULL, &slots_count); 42 | fail_if_err (err); 43 | 44 | if (slots_count == 0) 45 | { 46 | printf ("Skipping test because no token is present.\n"); 47 | return 77; 48 | } 49 | 50 | printf ("Number of slots with tokens: %lu\n", slots_count); 51 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 52 | if (!slots) 53 | fail_if_err (CKR_HOST_MEMORY); 54 | 55 | sessions = malloc (sizeof (CK_SESSION_HANDLE) * slots_count); 56 | if (!sessions) 57 | fail_if_err (CKR_HOST_MEMORY); 58 | 59 | err = C_GetSlotList (true, slots, &slots_count); 60 | fail_if_err (err); 61 | 62 | for (i = 0; i < slots_count; i++) 63 | { 64 | CK_SESSION_INFO info; 65 | 66 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 67 | err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, 68 | &sessions[i]); 69 | fail_if_err (err); 70 | 71 | printf (" Session ID: %lu\n", sessions[i]); 72 | 73 | err = C_GetSessionInfo (sessions[i], &info); 74 | fail_if_err (err); 75 | 76 | printf (" Slot ID: %lu\n", info.slotID); 77 | printf (" State: %s\n", session_state_str (info.state)); 78 | printf (" Flags: %#lx", info.flags); 79 | 80 | if (info.flags) 81 | { 82 | bool any = false; 83 | CK_FLAGS xflags = 0; 84 | 85 | printf (" == "); 86 | #define DO_FLAG(sym) \ 87 | if (info.flags & sym) \ 88 | { \ 89 | printf ("%s" #sym, any ? " | " : ""); \ 90 | any = true; \ 91 | xflags |= sym; \ 92 | } 93 | DO_FLAG (CKF_RW_SESSION); 94 | DO_FLAG (CKF_SERIAL_SESSION); 95 | 96 | xflags = info.flags & ~xflags; 97 | if (xflags) 98 | printf ("%s%#lx", any ? " | " : "", xflags); 99 | } 100 | printf ("\n"); 101 | printf (" Device Error: %lu\n", info.ulDeviceError); 102 | 103 | fail_if_err (info.slotID != slots[i] ? CKR_GENERAL_ERROR : 0); 104 | fail_if_err (info.state != CKS_RO_PUBLIC_SESSION 105 | ? CKR_GENERAL_ERROR : 0); 106 | fail_if_err (info.flags != CKF_SERIAL_SESSION ? CKR_GENERAL_ERROR : 0); 107 | fail_if_err (info.ulDeviceError ? CKR_GENERAL_ERROR : 0); 108 | } 109 | 110 | for (i = 0; i < slots_count; i++) 111 | { 112 | err = C_CloseSession (sessions[i]); 113 | fail_if_err (err); 114 | } 115 | 116 | return 0; 117 | } 118 | -------------------------------------------------------------------------------- /tests/t-getfunctionlist.c: -------------------------------------------------------------------------------- 1 | /* t-getfunctionlist.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | bool mismatch = false; 27 | CK_FUNCTION_LIST_PTR fl; 28 | 29 | #define DO_ONE(fnc) printf (#fnc ": %p %c= %p \n", fnc, \ 30 | fl->fnc == fnc ? '=' : (mismatch = true, '!'), fl->fnc) 31 | 32 | int 33 | main (int argc, char *argv[]) 34 | { 35 | CK_RV err; 36 | 37 | (void) argc; 38 | (void) argv; 39 | 40 | /* This is the only function that can be called without 41 | initialization. */ 42 | err = C_GetFunctionList (&fl); 43 | fail_if_err (err); 44 | 45 | /* Check for each function if the member in the function list is 46 | identical to the exported symbol. */ 47 | DO_ONE (C_CancelFunction); 48 | DO_ONE (C_CloseAllSessions); 49 | DO_ONE (C_CloseSession); 50 | DO_ONE (C_CopyObject); 51 | DO_ONE (C_CreateObject); 52 | DO_ONE (C_Decrypt); 53 | DO_ONE (C_DecryptDigestUpdate); 54 | DO_ONE (C_DecryptFinal); 55 | DO_ONE (C_DecryptInit); 56 | DO_ONE (C_DecryptUpdate); 57 | DO_ONE (C_DecryptVerifyUpdate); 58 | DO_ONE (C_DeriveKey); 59 | DO_ONE (C_DestroyObject); 60 | DO_ONE (C_Digest); 61 | DO_ONE (C_DigestEncryptUpdate); 62 | DO_ONE (C_DigestFinal); 63 | DO_ONE (C_DigestInit); 64 | DO_ONE (C_DigestKey); 65 | DO_ONE (C_DigestUpdate); 66 | DO_ONE (C_Encrypt); 67 | DO_ONE (C_EncryptFinal); 68 | DO_ONE (C_EncryptInit); 69 | DO_ONE (C_EncryptUpdate); 70 | DO_ONE (C_Finalize); 71 | DO_ONE (C_FindObjects); 72 | DO_ONE (C_FindObjectsFinal); 73 | DO_ONE (C_FindObjectsInit); 74 | DO_ONE (C_GenerateKey); 75 | DO_ONE (C_GenerateKeyPair); 76 | DO_ONE (C_GenerateRandom); 77 | DO_ONE (C_GetAttributeValue); 78 | DO_ONE (C_GetFunctionList); 79 | DO_ONE (C_GetFunctionStatus); 80 | DO_ONE (C_GetInfo); 81 | DO_ONE (C_GetMechanismInfo); 82 | DO_ONE (C_GetMechanismList); 83 | DO_ONE (C_GetObjectSize); 84 | DO_ONE (C_GetOperationState); 85 | DO_ONE (C_GetSessionInfo); 86 | DO_ONE (C_GetSlotInfo); 87 | DO_ONE (C_GetSlotList); 88 | DO_ONE (C_GetTokenInfo); 89 | DO_ONE (C_InitPIN); 90 | DO_ONE (C_InitToken); 91 | DO_ONE (C_Initialize); 92 | DO_ONE (C_Login); 93 | DO_ONE (C_Logout); 94 | DO_ONE (C_OpenSession); 95 | DO_ONE (C_SeedRandom); 96 | DO_ONE (C_SetAttributeValue); 97 | DO_ONE (C_SetOperationState); 98 | DO_ONE (C_SetPIN); 99 | DO_ONE (C_Sign); 100 | DO_ONE (C_SignEncryptUpdate); 101 | DO_ONE (C_SignFinal); 102 | DO_ONE (C_SignInit); 103 | DO_ONE (C_SignRecover); 104 | DO_ONE (C_SignRecoverInit); 105 | DO_ONE (C_SignUpdate); 106 | DO_ONE (C_UnwrapKey); 107 | DO_ONE (C_Verify); 108 | DO_ONE (C_VerifyFinal); 109 | DO_ONE (C_VerifyInit); 110 | DO_ONE (C_VerifyRecover); 111 | DO_ONE (C_VerifyRecoverInit); 112 | DO_ONE (C_VerifyUpdate); 113 | DO_ONE (C_WaitForSlotEvent); 114 | DO_ONE (C_WrapKey); 115 | 116 | if (mismatch) 117 | fail ("Some members of the function list do not match symbol value"); 118 | 119 | return 0; 120 | } 121 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | # Emacs, please get me into -*- org -*- mode. 2 | #+STARTUP: showall 3 | 4 | * Manual: 5 | ** Some FIXME's which need attention. 6 | ** The pictures in info output do not exist. 7 | 8 | * Bugs or misfeatures: 9 | ** Mozilla presents the other certificates in "Websites". Only the 10 | first one is presented in the certicate manager under "Personal". 11 | ** Mozilla does not unload the right security token!!! 12 | ** Duplicate certificates should be removed from the object list (this 13 | can occur when including all certificate chains). 14 | ** Windows: Find thread-safe replacement for localtime_r and timegm. 15 | 16 | * Missing features: 17 | ** Add canonical gnupg logging module. 18 | This is meanwhile part of libgpg-error which is already in use. 19 | ** Mozilla ignores the CKA_TRUSTED attribute to certificates, so 20 | exporting the information from GPGSM (ISTRUSTED) will not be 21 | useful. It's unclear if this can be improved in a meaningful way. 22 | 23 | * Standard ambiguities, or non-conformance in the applications: 24 | ** If the token is removed, the current sessions are closed. If then 25 | a new token is inserted, and the application calls C_OpenSession, a 26 | previously used session handle may be reused. It is not clear what 27 | behaviour the standard specifies in this case. 28 | 29 | ** Mozilla NSS has this comment (and relies on the assumption): 30 | "check to see if the module has added new slots. PKCS 11 v2.20 31 | allows for modules to add new slots, but never remove them. Slots 32 | cannot be added between a call to C_GetSlotLlist(Flag, NULL, 33 | &count) and the subsequent C_GetSlotList(flag, &data, &count) so 34 | that the array doesn't accidently grow on the caller. It is 35 | permissible for the slots to increase between successive calls with 36 | NULL to get the size." 37 | 38 | My reading of the spec is quite different. I do not think it does 39 | say that the slot list can not shrink, at least it does not say 40 | explicitely. Maybe it is a tacit assumption, because the interface 41 | is obviously broken if the list shrinks. However, the spec says: 42 | 43 | "All slots which C_GetSlotList reports must be able to be queried as 44 | valid slots by C_GetSlotInfo. Furthermore, the set of slots 45 | accessible through a Cryptoki library is checked at the time that 46 | C_GetSlotList, for list length prediction (NULL pSlotList argument) 47 | is called. If an application calls C_GetSlotList with a non-NULL 48 | pSlotList, and then the user adds or removes a hardware device, the 49 | changed slot list will only be visible and effective if 50 | C_GetSlotList is called again with NULL. Even if C_GetSlotList is 51 | successfully called this way, it may or may not be the case that 52 | the changed slot list will be successfully recognized depending on 53 | the library implementation. On some platforms, or earlier PKCS11 54 | compliant libraries, it may be necessary to successfully call 55 | C_Initialize or to restart the entire system." 56 | 57 | Note the phrase "user adds or removes a hardware device" and "the 58 | changed slot list". This implies that removal of a hardware device 59 | could lead to a shrinking slot list. If this is true, then the note 60 | in the NSS code is incorrect, and the NSS code will break if a 61 | driver shrinks the slot list. 62 | 63 | However, as long as the assumption is made, we have to comply. 64 | 65 | * Website: 66 | ** Border picture width constant hard-coded in CSS. 67 | * Copyright notice 68 | Copyright 2006 g10 Code GmbH 69 | 70 | This file is free software; as a special exception the author gives 71 | unlimited permission to copy and/or distribute it, with or without 72 | modifications, as long as this notice is preserved. 73 | 74 | This file is distributed in the hope that it will be useful, but 75 | WITHOUT ANY WARRANTY, to the extent permitted by law; without even the 76 | implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 77 | PURPOSE. 78 | -------------------------------------------------------------------------------- /src/p11-gettokeninfo.c: -------------------------------------------------------------------------------- 1 | /* p11-gettokeninfo.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "locking.h" 28 | #include "support.h" 29 | #include "settings.h" 30 | #include "slots.h" 31 | 32 | 33 | CK_RV CK_SPEC 34 | C_GetTokenInfo (CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) 35 | { 36 | CK_RV err = CKR_OK; 37 | slot_iterator_t slot; 38 | int len; 39 | int max; 40 | 41 | err = scute_global_lock (); 42 | if (err) 43 | return err; 44 | 45 | err = slots_lookup (slotID, &slot); 46 | if (err) 47 | goto out; 48 | 49 | if (!slot_token_present (slot)) 50 | { 51 | err = CKR_TOKEN_NOT_PRESENT; 52 | goto out; 53 | } 54 | 55 | scute_copy_string (pInfo->label, slot_token_label (slot), 32); 56 | scute_copy_string (pInfo->manufacturerID, 57 | slot_token_manufacturer (slot), 32); 58 | scute_copy_string (pInfo->model, slot_token_application (slot), 16); 59 | scute_copy_string (pInfo->serialNumber, slot_token_serial (slot), 16); 60 | 61 | pInfo->flags = CKF_TOKEN_INITIALIZED 62 | | CKF_PROTECTED_AUTHENTICATION_PATH | CKF_WRITE_PROTECTED 63 | | CKF_USER_PIN_INITIALIZED; 64 | 65 | if (slot_token_has_rng (slot)) 66 | pInfo->flags |= CKF_RNG; 67 | 68 | /* FIXME: CKF_USER_PIN_INITIALIZED only if PIN is not default pin? 69 | FIXME: CKF_LOGIN_REQUIRED needed? We could implement login via 70 | the "SCD CHECKPIN" command. I am not sure how this mixes with 71 | CKF_PROTECTED_AUTHENTICATION_PATH. 72 | 73 | Not supported: 74 | CKF_RESTORE_KEY_NOT_NEEDED, CKF_DUAL_CRYPTO_OPERATIONS. 75 | 76 | FIXME: We can support those, but do we worry about SO operations? 77 | CKF_SO_PIN_COUNT_LOW, CKF_SO_PIN_FINAL_TRY, CKF_SO_PIN_LOCKED. 78 | 79 | Not supported: CKF_USER_PIN_TO_BE_CHANGED, CKF_SO_PIN_TO_BE_CHANGED. */ 80 | 81 | slot_token_pincount (slot, &max, &len); 82 | if (len < max) 83 | pInfo->flags |= CKF_USER_PIN_COUNT_LOW; 84 | if (len == 1) 85 | pInfo->flags |= CKF_USER_PIN_FINAL_TRY; 86 | else if (len == 0) 87 | pInfo->flags |= CKF_USER_PIN_LOCKED; 88 | 89 | pInfo->ulMaxSessionCount = CK_EFFECTIVELY_INFINITE; 90 | pInfo->ulSessionCount = CK_UNAVAILABLE_INFORMATION; 91 | pInfo->ulMaxRwSessionCount = CK_EFFECTIVELY_INFINITE; 92 | pInfo->ulRwSessionCount = CK_UNAVAILABLE_INFORMATION; 93 | slot_token_maxpinlen (slot, &pInfo->ulMaxPinLen, &pInfo->ulMinPinLen); 94 | 95 | /* FIXME: Get the data from SCD? */ 96 | pInfo->ulTotalPublicMemory = CK_UNAVAILABLE_INFORMATION; 97 | pInfo->ulFreePublicMemory = CK_UNAVAILABLE_INFORMATION; 98 | pInfo->ulTotalPrivateMemory = CK_UNAVAILABLE_INFORMATION; 99 | pInfo->ulFreePrivateMemory = CK_UNAVAILABLE_INFORMATION; 100 | slot_token_version (slot, &pInfo->hardwareVersion.major, 101 | &pInfo->hardwareVersion.minor, 102 | &pInfo->firmwareVersion.major, 103 | &pInfo->firmwareVersion.minor); 104 | scute_copy_string (pInfo->utcTime, "0000000000000000", 16); 105 | 106 | out: 107 | scute_global_unlock (); 108 | return err; 109 | } 110 | -------------------------------------------------------------------------------- /tests/t-getmechanisminfo.c: -------------------------------------------------------------------------------- 1 | /* t-getmechanismlist.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | 27 | int 28 | main (int argc, char *argv[]) 29 | { 30 | CK_RV err; 31 | CK_SLOT_ID_PTR slots; 32 | CK_ULONG slots_count; 33 | unsigned int i; 34 | 35 | (void) argc; 36 | (void) argv; 37 | 38 | init_cryptoki (); 39 | 40 | err = C_GetSlotList (true, NULL, &slots_count); 41 | fail_if_err (err); 42 | 43 | if (slots_count == 0) 44 | { 45 | printf ("Skipping test because no token is present.\n"); 46 | return 77; 47 | } 48 | 49 | printf ("Number of slots with tokens: %lu\n", slots_count); 50 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 51 | if (!slots) 52 | fail_if_err (CKR_HOST_MEMORY); 53 | 54 | err = C_GetSlotList (true, slots, &slots_count); 55 | fail_if_err (err); 56 | 57 | for (i = 0; i < slots_count; i++) 58 | { 59 | CK_MECHANISM_TYPE_PTR mechanisms; 60 | CK_ULONG mechanisms_count; 61 | unsigned int j; 62 | 63 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 64 | 65 | err = C_GetMechanismList (slots[i], NULL, &mechanisms_count); 66 | fail_if_err (err); 67 | 68 | printf (" Mechanisms: %lu\n", mechanisms_count); 69 | mechanisms = malloc (sizeof (CK_MECHANISM_TYPE) * mechanisms_count); 70 | if (!mechanisms) 71 | fail_if_err (CKR_HOST_MEMORY); 72 | 73 | err = C_GetMechanismList (slots[i], mechanisms, &mechanisms_count); 74 | fail_if_err (err); 75 | 76 | for (j = 0; j < mechanisms_count; j++) 77 | { 78 | CK_MECHANISM_INFO info; 79 | 80 | printf (" %2i. %s\n", j, mechanism_type_str (mechanisms[j])); 81 | 82 | err = C_GetMechanismInfo (slots[i], mechanisms[j], &info); 83 | fail_if_err (err); 84 | 85 | printf (" Minimum key size: %lu\n", info.ulMinKeySize); 86 | printf (" Maximum key size: %lu\n", info.ulMaxKeySize); 87 | printf (" Flags: %#lx", info.flags); 88 | 89 | if (info.flags) 90 | { 91 | bool any = false; 92 | CK_FLAGS xflags = 0; 93 | 94 | printf (" == "); 95 | #define DO_FLAG(sym) \ 96 | if (info.flags & sym) \ 97 | { \ 98 | printf ("%s" #sym, any ? " | " : ""); \ 99 | any = true; \ 100 | xflags |= sym; \ 101 | } 102 | DO_FLAG (CKF_HW); 103 | DO_FLAG (CKF_ENCRYPT); 104 | DO_FLAG (CKF_DECRYPT); 105 | DO_FLAG (CKF_DIGEST); 106 | DO_FLAG (CKF_SIGN); 107 | DO_FLAG (CKF_SIGN_RECOVER); 108 | DO_FLAG (CKF_VERIFY); 109 | DO_FLAG (CKF_VERIFY_RECOVER); 110 | DO_FLAG (CKF_GENERATE); 111 | DO_FLAG (CKF_GENERATE_KEY_PAIR); 112 | DO_FLAG (CKF_WRAP); 113 | DO_FLAG (CKF_UNWRAP); 114 | DO_FLAG (CKF_DERIVE); 115 | DO_FLAG (CKF_EXTENSION); 116 | 117 | xflags = info.flags & ~xflags; 118 | if (xflags) 119 | printf ("%s%#lx", any ? " | " : "", xflags); 120 | } 121 | printf ("\n"); 122 | } 123 | free (mechanisms); 124 | } 125 | 126 | return 0; 127 | } 128 | -------------------------------------------------------------------------------- /tests/t-auth.c: -------------------------------------------------------------------------------- 1 | /* t-auth.c - Regression test. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | #include "t-support.h" 25 | 26 | CK_RV 27 | dump_one (unsigned char *data, int size) 28 | { 29 | bool some; 30 | int i; 31 | 32 | some = false; 33 | for (i = 0; i < size; i++) 34 | { 35 | if (some == false) 36 | { 37 | printf (" "); 38 | some = true; 39 | } 40 | printf ("%02x", data[i]); 41 | if (((i + 1) % 32) == 0) 42 | { 43 | printf ("\n"); 44 | some = false; 45 | } 46 | } 47 | if (some) 48 | printf ("\n"); 49 | 50 | return 0; 51 | } 52 | 53 | 54 | CK_RV 55 | sign_with_object (CK_SESSION_HANDLE session, CK_OBJECT_HANDLE object) 56 | { 57 | CK_RV err; 58 | CK_MECHANISM mechanism = { CKM_RSA_PKCS, NULL_PTR, 0 }; 59 | CK_BYTE data[36] = "01234567890123456789012345678901234"; 60 | CK_BYTE sig[256]; 61 | CK_ULONG sig_len = sizeof (sig); 62 | 63 | err = C_SignInit (session, &mechanism, object); 64 | if (err) 65 | return err; 66 | 67 | err = C_Sign (session, data, sizeof (data), sig, &sig_len); 68 | if (err) 69 | return err; 70 | 71 | printf (" Sign Result: Length %lu\n", sig_len); 72 | err = dump_one (sig, sig_len); 73 | if (err) 74 | return err; 75 | 76 | return 0; 77 | } 78 | 79 | 80 | int 81 | main (int argc, char *argv[]) 82 | { 83 | CK_RV err; 84 | CK_SLOT_ID_PTR slots; 85 | CK_ULONG slots_count; 86 | unsigned int i; 87 | 88 | (void) argc; 89 | (void) argv; 90 | 91 | init_cryptoki (); 92 | 93 | err = C_GetSlotList (true, NULL, &slots_count); 94 | fail_if_err (err); 95 | 96 | if (slots_count == 0) 97 | { 98 | printf ("Skipping test because no token is present.\n"); 99 | return 77; 100 | } 101 | 102 | printf ("Number of slots with tokens: %lu\n", slots_count); 103 | slots = malloc (sizeof (CK_SLOT_ID) * slots_count); 104 | if (!slots) 105 | fail_if_err (CKR_HOST_MEMORY); 106 | 107 | err = C_GetSlotList (true, slots, &slots_count); 108 | fail_if_err (err); 109 | 110 | for (i = 0; i < slots_count; i++) 111 | { 112 | CK_SESSION_HANDLE session; 113 | CK_OBJECT_CLASS obj_class = CKO_PRIVATE_KEY; 114 | CK_ATTRIBUTE attr[] = { { CKA_CLASS, &obj_class, sizeof (obj_class) } }; 115 | CK_OBJECT_HANDLE object; 116 | CK_ULONG count; 117 | 118 | printf ("%2i. Slot ID %lu\n", i, slots[i]); 119 | err = C_OpenSession (slots[i], CKF_SERIAL_SESSION, NULL, NULL, 120 | &session); 121 | fail_if_err (err); 122 | 123 | printf (" Session ID: %lu\n", session); 124 | 125 | err = C_FindObjectsInit (session, attr, DIM (attr)); 126 | fail_if_err (err); 127 | 128 | do 129 | { 130 | err = C_FindObjects (session, &object, 1, &count); 131 | fail_if_err (err); 132 | 133 | if (count) 134 | { 135 | printf (" Object Handle: %lu\n", object); 136 | 137 | err = sign_with_object (session, object); 138 | fail_if_err (err); 139 | } 140 | } 141 | while (count); 142 | 143 | err = C_FindObjectsFinal (session); 144 | fail_if_err (err); 145 | 146 | err = C_CloseSession (session); 147 | fail_if_err (err); 148 | } 149 | 150 | return 0; 151 | } 152 | -------------------------------------------------------------------------------- /src/p11-getfunctionlist.c: -------------------------------------------------------------------------------- 1 | /* p11-getfunctionlist.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include "cryptoki.h" 26 | 27 | #include "settings.h" 28 | 29 | 30 | /* The list of exported functions. */ 31 | static CK_FUNCTION_LIST function_list = 32 | { 33 | version: { major: VERSION_MAJOR, minor: VERSION_MINOR }, 34 | C_Initialize: C_Initialize, 35 | C_Finalize: C_Finalize, 36 | C_GetInfo: C_GetInfo, 37 | C_GetFunctionList: C_GetFunctionList, 38 | C_GetSlotList: C_GetSlotList, 39 | C_GetSlotInfo: C_GetSlotInfo, 40 | C_GetTokenInfo: C_GetTokenInfo, 41 | C_GetMechanismList: C_GetMechanismList, 42 | C_GetMechanismInfo: C_GetMechanismInfo, 43 | C_InitToken: C_InitToken, 44 | C_InitPIN: C_InitPIN, 45 | C_SetPIN: C_SetPIN, 46 | C_OpenSession: C_OpenSession, 47 | C_CloseSession: C_CloseSession, 48 | C_CloseAllSessions: C_CloseAllSessions, 49 | C_GetSessionInfo: C_GetSessionInfo, 50 | C_GetOperationState: C_GetOperationState, 51 | C_SetOperationState: C_SetOperationState, 52 | C_Login: C_Login, 53 | C_Logout: C_Logout, 54 | C_CreateObject: C_CreateObject, 55 | C_CopyObject: C_CopyObject, 56 | C_DestroyObject: C_DestroyObject, 57 | C_GetObjectSize: C_GetObjectSize, 58 | C_GetAttributeValue: C_GetAttributeValue, 59 | C_SetAttributeValue: C_SetAttributeValue, 60 | C_FindObjectsInit: C_FindObjectsInit, 61 | C_FindObjects: C_FindObjects, 62 | C_FindObjectsFinal: C_FindObjectsFinal, 63 | C_EncryptInit: C_EncryptInit, 64 | C_Encrypt: C_Encrypt, 65 | C_EncryptUpdate: C_EncryptUpdate, 66 | C_EncryptFinal: C_EncryptFinal, 67 | C_DecryptInit: C_DecryptInit, 68 | C_Decrypt: C_Decrypt, 69 | C_DecryptUpdate: C_DecryptUpdate, 70 | C_DecryptFinal: C_DecryptFinal, 71 | C_DigestInit: C_DigestInit, 72 | C_Digest: C_Digest, 73 | C_DigestUpdate: C_DigestUpdate, 74 | C_DigestKey: C_DigestKey, 75 | C_DigestFinal: C_DigestFinal, 76 | C_SignInit: C_SignInit, 77 | C_Sign: C_Sign, 78 | C_SignUpdate: C_SignUpdate, 79 | C_SignFinal: C_SignFinal, 80 | C_SignRecoverInit: C_SignRecoverInit, 81 | C_SignRecover: C_SignRecover, 82 | C_VerifyInit: C_VerifyInit, 83 | C_Verify: C_Verify, 84 | C_VerifyUpdate: C_VerifyUpdate, 85 | C_VerifyFinal: C_VerifyFinal, 86 | C_VerifyRecoverInit: C_VerifyRecoverInit, 87 | C_VerifyRecover: C_VerifyRecover, 88 | C_DigestEncryptUpdate: C_DigestEncryptUpdate, 89 | C_DecryptDigestUpdate: C_DecryptDigestUpdate, 90 | C_SignEncryptUpdate: C_SignEncryptUpdate, 91 | C_DecryptVerifyUpdate: C_DecryptVerifyUpdate, 92 | C_GenerateKey: C_GenerateKey, 93 | C_GenerateKeyPair: C_GenerateKeyPair, 94 | C_WrapKey: C_WrapKey, 95 | C_UnwrapKey: C_UnwrapKey, 96 | C_DeriveKey: C_DeriveKey, 97 | C_SeedRandom: C_SeedRandom, 98 | C_GenerateRandom: C_GenerateRandom, 99 | C_GetFunctionStatus: C_GetFunctionStatus, 100 | C_CancelFunction: C_CancelFunction, 101 | C_WaitForSlotEvent: C_WaitForSlotEvent 102 | }; 103 | 104 | 105 | CK_RV CK_SPEC 106 | C_GetFunctionList (CK_FUNCTION_LIST_PTR_PTR ppFunctionList) 107 | { 108 | /* This is one of the few functions which do not need to take the 109 | global lock. */ 110 | 111 | if (ppFunctionList == NULL_PTR) 112 | return CKR_ARGUMENTS_BAD; 113 | 114 | *ppFunctionList = &function_list; 115 | 116 | return CKR_OK; 117 | } 118 | -------------------------------------------------------------------------------- /src/p11-findobjectsinit.c: -------------------------------------------------------------------------------- 1 | /* p11-findobjectsinit.c - Cryptoki implementation. 2 | * Copyright (C) 2006 g10 Code GmbH 3 | * 4 | * This file is part of Scute. 5 | * 6 | * Scute is free software; you can redistribute it and/or modify it 7 | * under the terms of the GNU Lesser General Public License as 8 | * published by the Free Software Foundation; either version 2.1 of 9 | * the License, or (at your option) any later version. 10 | * 11 | * Scute is distributed in the hope that it will be useful, but 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14 | * Lesser General Public License for more details. 15 | * 16 | * You should have received a copy of the GNU Lesser General Public 17 | * License along with this program; if not, see . 18 | * SPDX-License-Identifier: LGPL-2.1-or-later 19 | */ 20 | 21 | #if HAVE_CONFIG_H 22 | #include 23 | #endif 24 | 25 | #include 26 | #include 27 | #include 28 | 29 | #include "cryptoki.h" 30 | 31 | #include "locking.h" 32 | #include "error-mapping.h" 33 | #include "slots.h" 34 | #include "debug.h" 35 | 36 | 37 | CK_RV CK_SPEC 38 | C_FindObjectsInit (CK_SESSION_HANDLE hSession, 39 | CK_ATTRIBUTE_PTR pTemplate, CK_ULONG ulCount) 40 | { 41 | CK_RV err = CKR_OK; 42 | slot_iterator_t slot; 43 | session_iterator_t session; 44 | object_iterator_t object; 45 | object_iterator_t *search_result; 46 | int search_result_len = 0; 47 | 48 | if (ulCount && pTemplate == NULL_PTR) 49 | return CKR_ARGUMENTS_BAD; 50 | 51 | err = scute_global_lock (); 52 | if (err) 53 | return err; 54 | 55 | err = slots_lookup_session (hSession, &slot, &session); 56 | if (err) 57 | goto out; 58 | 59 | err = slot_get_object_count (slot, &search_result_len); 60 | if (err) 61 | goto out; 62 | 63 | search_result = malloc (search_result_len * sizeof (object_iterator_t)); 64 | if (!search_result) 65 | { 66 | err = scute_sys_to_ck (errno); 67 | goto out; 68 | } 69 | search_result_len = 0; 70 | 71 | err = objects_iterate_first (slot, &object); 72 | if (err) 73 | { 74 | free (search_result); 75 | goto out; 76 | } 77 | 78 | while (!objects_iterate_last (slot, &object) && !err) 79 | { 80 | CK_ATTRIBUTE_PTR attr; 81 | CK_ULONG attr_count; 82 | 83 | err = slot_get_object (slot, object, &attr, &attr_count); 84 | if (!err) 85 | { 86 | CK_ULONG count = ulCount; 87 | 88 | /* For each template attribute, check if it matches the 89 | * object. */ 90 | while (count--) 91 | { 92 | CK_ULONG i; 93 | 94 | for (i = 0; i < attr_count; i++) 95 | if (attr[i].type == pTemplate[count].type) 96 | break; 97 | 98 | /* Lots of ways not to match. */ 99 | if (i == attr_count) 100 | break; 101 | if (pTemplate[count].ulValueLen != attr[i].ulValueLen) 102 | break; 103 | if (memcmp (pTemplate[count].pValue, attr[i].pValue, 104 | attr[i].ulValueLen)) 105 | break; 106 | } 107 | 108 | if (count == (CK_ULONG) -1) 109 | { 110 | /* Got a match. */ 111 | search_result[search_result_len++] = object; 112 | } 113 | 114 | err = objects_iterate_next (slot, &object); 115 | } 116 | } 117 | 118 | if (err) 119 | { 120 | free (search_result); 121 | goto out; 122 | } 123 | 124 | if (!search_result_len) 125 | { 126 | /* We do not yet known about this object. If CKA_ISSUER and 127 | * CKA_SERIAL_NUMBER was requested, try to look it up via gpgsm. */ 128 | int i, issuer_idx, serialno_idx; 129 | 130 | issuer_idx = serialno_idx = -1; 131 | for (i=0; i < ulCount; i++) 132 | { 133 | if (pTemplate[i].type == CKA_ISSUER) 134 | issuer_idx = i; 135 | else if (pTemplate[i].type == CKA_SERIAL_NUMBER) 136 | serialno_idx = i; 137 | } 138 | if (ulCount == 2 && issuer_idx >= 0 && serialno_idx >= 0) 139 | { 140 | DEBUG (DBG_INFO, "Nothing found - should try sn+issuer"); 141 | } 142 | 143 | } 144 | 145 | err = session_set_search_result (slot, session, search_result, 146 | search_result_len); 147 | 148 | out: 149 | scute_global_unlock (); 150 | return err; 151 | } 152 | -------------------------------------------------------------------------------- /src/sexp-parse.h: -------------------------------------------------------------------------------- 1 | /* sexp-parse.h - S-expression helper functions 2 | * Copyright (C) 2002, 2003, 2007 Free Software Foundation, Inc. 3 | * Copyright (C) 2002, 2003, 2007 Werner Koch 4 | * 5 | * This file is part of Scute. 6 | * 7 | * Scute is free software; you can redistribute it and/or modify it 8 | * under the terms of the GNU Lesser General Public License as 9 | * published by the Free Software Foundation; either version 2.1 of 10 | * the License, or (at your option) any later version. 11 | * 12 | * Scute is distributed in the hope that it will be useful, but 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | * Lesser General Public License for more details. 16 | * 17 | * You should have received a copy of the GNU Lesser General Public 18 | * License along with this program; if not, see . 19 | * SPDX-License-Identifier: LGPL-2.1-or-later 20 | */ 21 | 22 | /* Note that this file has been taken from GnuPG and re-licensed to 23 | * the LGPL. See the commit log for details. */ 24 | 25 | #ifndef SEXP_PARSE_H 26 | #define SEXP_PARSE_H 27 | 28 | #include 29 | 30 | 31 | /* Return the length of the next S-Exp part and update the pointer to 32 | the first data byte. 0 is returned on error */ 33 | static inline size_t 34 | snext (unsigned char const **buf) 35 | { 36 | const unsigned char *s; 37 | int n; 38 | 39 | s = *buf; 40 | for (n=0; *s && *s != ':' && (*s >= '0' && *s <= '9'); s++) 41 | n = n*10 + (*s - '0'); 42 | if (!n || *s != ':') 43 | return 0; /* we don't allow empty lengths */ 44 | *buf = s+1; 45 | return n; 46 | } 47 | 48 | /* Skip over the S-Expression BUF points to and update BUF to point to 49 | the chacter right behind. DEPTH gives the initial number of open 50 | lists and may be passed as a positive number to skip over the 51 | remainder of an S-Expression if the current position is somewhere 52 | in an S-Expression. The function may return an error code if it 53 | encounters an impossible condition. */ 54 | static inline gpg_error_t 55 | sskip (unsigned char const **buf, int *depth) 56 | { 57 | const unsigned char *s = *buf; 58 | size_t n; 59 | int d = *depth; 60 | 61 | while (d > 0) 62 | { 63 | if (*s == '(') 64 | { 65 | d++; 66 | s++; 67 | } 68 | else if (*s == ')') 69 | { 70 | d--; 71 | s++; 72 | } 73 | else 74 | { 75 | if (!d) 76 | return gpg_error (GPG_ERR_INV_SEXP); 77 | n = snext (&s); 78 | if (!n) 79 | return gpg_error (GPG_ERR_INV_SEXP); 80 | s += n; 81 | } 82 | } 83 | *buf = s; 84 | *depth = d; 85 | return 0; 86 | } 87 | 88 | 89 | /* Check whether the string at the address BUF points to matches 90 | the token. Return true on match and update BUF to point behind the 91 | token. Return false and do not update the buffer if it does not 92 | match. */ 93 | static inline int 94 | smatch (unsigned char const **buf, size_t buflen, const char *token) 95 | { 96 | size_t toklen = strlen (token); 97 | 98 | if (buflen != toklen || memcmp (*buf, token, toklen)) 99 | return 0; 100 | *buf += toklen; 101 | return 1; 102 | } 103 | 104 | /* Format VALUE for use as the length indicatior of an S-expression. 105 | The caller needs to provide a buffer HELP_BUFFER wth a length of 106 | HELP_BUFLEN. The return value is a pointer into HELP_BUFFER with 107 | the formatted length string. The colon and a trailing nul are 108 | appended. HELP_BUFLEN must be at least 3 - a more useful value is 109 | 15. If LENGTH is not NULL, the LENGTH of the resulting string 110 | (excluding the terminating nul) is stored at that address. */ 111 | static inline char * 112 | smklen (char *help_buffer, size_t help_buflen, size_t value, size_t *length) 113 | { 114 | char *p = help_buffer + help_buflen; 115 | 116 | if (help_buflen >= 3) 117 | { 118 | *--p = 0; 119 | *--p = ':'; 120 | do 121 | { 122 | *--p = '0' + (value % 10); 123 | value /= 10; 124 | } 125 | while (value && p > help_buffer); 126 | } 127 | 128 | if (length) 129 | *length = (help_buffer + help_buflen) - p; 130 | return p; 131 | } 132 | 133 | 134 | #endif /*SEXP_PARSE_H*/ 135 | --------------------------------------------------------------------------------