54
54
import java .util .ServiceConfigurationError ;
55
55
import java .util .ServiceLoader ;
56
56
import java .util .Set ;
57
+ import java .util .stream .Collectors ;
57
58
import java .util .stream .Stream ;
58
59
59
60
import javax .crypto .SecretKey ;
60
61
import javax .crypto .spec .SecretKeySpec ;
61
62
62
63
import jdk .test .lib .Platform ;
64
+ import jdk .test .lib .Utils ;
63
65
import jdk .test .lib .artifacts .Artifact ;
64
66
import jdk .test .lib .artifacts .ArtifactResolver ;
65
67
import jdk .test .lib .artifacts .ArtifactResolverException ;
@@ -496,14 +498,13 @@ public static String getNssConfig() throws Exception {
496
498
return null ;
497
499
}
498
500
499
- String base = getBase ();
500
-
501
+ String nssConfigDir = copyNssFiles ();
501
502
String libfile = libdir + System .mapLibraryName (nss_library );
502
503
503
504
String customDBdir = System .getProperty ("CUSTOM_DB_DIR" );
504
505
String dbdir = (customDBdir != null ) ?
505
506
customDBdir :
506
- base + SEP + "nss" + SEP + "db" ;
507
+ nssConfigDir + SEP + "db" ;
507
508
// NSS always wants forward slashes for the config path
508
509
dbdir = dbdir .replace ('\\' , '/' );
509
510
@@ -513,7 +514,7 @@ public static String getNssConfig() throws Exception {
513
514
System .setProperty ("pkcs11test.nss.db" , dbdir );
514
515
return (customConfig != null ) ?
515
516
customConfig :
516
- base + SEP + "nss" + SEP + customConfigName ;
517
+ nssConfigDir + SEP + customConfigName ;
517
518
}
518
519
519
520
// Generate a vector of supported elliptic curves of a given provider
@@ -796,6 +797,31 @@ private static Path findNSSLibrary(Path path, Path libraryName) throws IOExcepti
796
797
}
797
798
}
798
799
800
+ //Copy the nss config files to the current directory for tests. Returns the destination path
801
+ private static String copyNssFiles () throws Exception {
802
+ String nss = "nss" ;
803
+ String db = "db" ;
804
+ Path nssDirSource = Path .of (getBase ()).resolve (nss );
805
+ Path nssDirDestination = Path .of ("." ).resolve (nss );
806
+
807
+ // copy files from nss directory
808
+ copyFiles (nssDirSource , nssDirDestination );
809
+ // copy files from nss/db directory
810
+ copyFiles (nssDirSource .resolve (db ), nssDirDestination .resolve (db ));
811
+ return nssDirDestination .toString ();
812
+ }
813
+
814
+ private static void copyFiles (Path dirSource , Path dirDestination ) throws IOException {
815
+ List <Path > sourceFiles = Arrays
816
+ .stream (dirSource .toFile ().listFiles ())
817
+ .filter (File ::isFile )
818
+ .map (File ::toPath )
819
+ .collect (Collectors .toList ());
820
+ List <Path > destFiles = Utils .copyFiles (sourceFiles , dirDestination ,
821
+ StandardCopyOption .REPLACE_EXISTING );
822
+ destFiles .forEach ((Path file ) -> file .toFile ().setWritable (true ));
823
+ }
824
+
799
825
public abstract void main (Provider p ) throws Exception ;
800
826
801
827
protected boolean skipTest (Provider p ) {
0 commit comments