[pkg-opensc-commit] [libp11] 28/239: add examples/ subdirectory.
Eric Dorland
eric at moszumanska.debian.org
Sat Oct 17 06:21:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
eric pushed a commit to branch master
in repository libp11.
commit cd30f1b6536ac2af62275225e4c01590aa25faf7
Author: Andreas Jellinghaus <andreas at ionisiert.de>
Date: Tue Aug 30 15:52:00 2005 +0000
add examples/ subdirectory.
---
Makefile.am | 2 +-
examples/Makefile | 7 +++++++
examples/README | 25 +++++++++++++++++++++++++
examples/auth.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 82 insertions(+), 1 deletion(-)
diff --git a/Makefile.am b/Makefile.am
index 829b127..56e0218 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -2,7 +2,7 @@
SUBDIRS = aclocal doc src rsaref .
-EXTRA_DIST = bootstrap depcomp
+EXTRA_DIST = bootstrap depcomp $(shell ls examples/{README,Makefile,*.c})
MAINTAINERCLEANFILES = \
Makefile.in config.h.in configure \
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000..fbe6529
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,7 @@
+CFLAGS=$(shell pkg-config --cflags libp11)
+LDFLAGS=$(shell pkg-config --libs libp11)
+
+all: auth
+
+clean:
+ rm auth
diff --git a/examples/README b/examples/README
new file mode 100644
index 0000000..6db711e
--- /dev/null
+++ b/examples/README
@@ -0,0 +1,25 @@
+Libp11 example code
+===================
+
+This directory contains some example code how to use libp11.
+Feel free to use this code in any way, it is public domain,
+not copyrighted.
+
+auth.c Example for authentication, i.e. get the first
+ token, get the first certificate, ask for pin,
+ login, sign some random data, and verify the
+ signature using the certificate/public key.
+
+For easy building see the Makefile in this directory. If you
+are using autoconf/automake/libtool, you might want to add
+to your configure.ac file:
+
+PKG_CHECK_MODULES([LIBP11], [libp11])
+
+and to your Makefile.am:
+
+bin_PROGRAMS = myapp
+
+myapp_CFLAGS = @LIBP11_CFLAGS@
+myapp_LIBADD = @LIBP11_LIBS@
+myapp_SOURCES = myapp.c
diff --git a/examples/auth.c b/examples/auth.c
new file mode 100644
index 0000000..2e6c5b1
--- /dev/null
+++ b/examples/auth.c
@@ -0,0 +1,49 @@
+#include <stdio.h>
+#include <libp11.h>
+
+int main(int argc, char **argv)
+{
+ PKCS11_CTX *ctx;
+ PKCS11_SLOT *slot;
+ unsigned char random[10];
+ int rc,len;
+
+ ctx = PKCS11_CTX_new();
+
+ /* load pkcs #11 module */
+ rc = PKCS11_CTX_load(ctx, "/home/aj/opensc/lib/opensc-pkcs11.so");
+ if (rc) {
+ fprintf(stderr, "loading pkcs11 engine failed\n");
+ rc=1;
+ goto nolib;
+ }
+
+ /* get first slot with a token */
+ slot = PKCS11_find_token(ctx);
+ if (!slot || !slot->token) {
+ fprintf(stderr, "no token available\n");
+ rc=2;
+ goto noslot;
+ }
+
+ /* get 10 random bytes */
+ len=sizeof(random);
+ rc = PKCS11_generate_random(slot, random, len);
+ if (rc < 0) {
+ fprintf(stderr,"generate_random failed: %d\n",rc);
+ rc=3;
+ goto norandom;
+ }
+
+ printf("%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n",
+ random[0], random[1], random[2], random[3], random[4],
+ random[5], random[6], random[7], random[8], random[9]);
+
+ rc=0;
+norandom:
+noslot:
+ PKCS11_CTX_unload(ctx);
+nolib:
+ PKCS11_CTX_free(ctx);
+ return rc;
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-opensc/libp11.git
More information about the pkg-opensc-commit
mailing list