@@ -36,6 +36,17 @@ let
3636 '';
3737 };
3838
39+ p11Auth = mkOption {
40+ default = config.security.pam.p11.enable;
41+ type = types.bool;
42+ description = ''
43+ If set, keys listed in
44+ <filename>~/.ssh/authorized_keys</filename> and
45+ <filename>~/.eid/authorized_certificates</filename>
46+ can be used to log in with the associated PKCS#11 tokens.
47+ '';
48+ };
49+
3950 u2fAuth = mkOption {
4051 default = config.security.pam.u2f.enable;
4152 type = types.bool;
@@ -352,6 +363,8 @@ let
352363 "auth sufficient ${pkgs.pam_ssh_agent_auth}/libexec/pam_ssh_agent_auth.so file=~/.ssh/authorized_keys:~/.ssh/authorized_keys2:/etc/ssh/authorized_keys.d/%u"}
353364 ${optionalString cfg.fprintAuth
354365 "auth sufficient ${pkgs.fprintd}/lib/security/pam_fprintd.so"}
366+ ${let p11 = config.security.pam.p11; in optionalString cfg.p11Auth
367+ "auth ${p11.control} ${pkgs.pam_p11}/lib/security/pam_p11.so ${pkgs.opensc}/lib/opensc-pkcs11.so"}
355368 ${let u2f = config.security.pam.u2f; in optionalString cfg.u2fAuth
356369 "auth ${u2f.control} ${pkgs.pam_u2f}/lib/security/pam_u2f.so ${optionalString u2f.debug "debug"} ${optionalString (u2f.authFile != null) "authfile=${u2f.authFile}"} ${optionalString u2f.interactive "interactive"} ${optionalString u2f.cue "cue"}"}
357370 ${optionalString cfg.usbAuth
@@ -566,6 +579,39 @@ in
566579
567580 security.pam.enableOTPW = mkEnableOption "the OTPW (one-time password) PAM module";
568581
582+ security.pam.p11 = {
583+ enable = mkOption {
584+ default = false;
585+ type = types.bool;
586+ description = ''
587+ Enables P11 PAM (<literal>pam_p11</literal>) module.
588+
589+ If set, users can log in with SSH keys and PKCS#11 tokens.
590+
591+ More information can be found <link
592+ xlink:href="https://github.com/OpenSC/pam_p11">here</link>.
593+ '';
594+ };
595+
596+ control = mkOption {
597+ default = "sufficient";
598+ type = types.enum [ "required" "requisite" "sufficient" "optional" ];
599+ description = ''
600+ This option sets pam "control".
601+ If you want to have multi factor authentication, use "required".
602+ If you want to use the PKCS#11 device instead of the regular password,
603+ use "sufficient".
604+
605+ Read
606+ <citerefentry>
607+ <refentrytitle>pam.conf</refentrytitle>
608+ <manvolnum>5</manvolnum>
609+ </citerefentry>
610+ for better understanding of this option.
611+ '';
612+ };
613+ };
614+
569615 security.pam.u2f = {
570616 enable = mkOption {
571617 default = false;
@@ -747,6 +793,7 @@ in
747793 ++ optionals config.krb5.enable [pam_krb5 pam_ccreds]
748794 ++ optionals config.security.pam.enableOTPW [ pkgs.otpw ]
749795 ++ optionals config.security.pam.oath.enable [ pkgs.oathToolkit ]
796+ ++ optionals config.security.pam.p11.enable [ pkgs.pam_p11 ]
750797 ++ optionals config.security.pam.u2f.enable [ pkgs.pam_u2f ];
751798
752799 boot.supportedFilesystems = optionals config.security.pam.enableEcryptfs [ "ecryptfs" ];