90-test_store.t 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547
  1. #! /usr/bin/env perl
  2. # Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved.
  3. #
  4. # Licensed under the Apache License 2.0 (the "License"). You may not use
  5. # this file except in compliance with the License. You can obtain a copy
  6. # in the file LICENSE in the source distribution or at
  7. # https://www.openssl.org/source/license.html
  8. use File::Spec::Functions;
  9. use File::Copy;
  10. use MIME::Base64;
  11. use OpenSSL::Test qw(:DEFAULT srctop_file srctop_dir bldtop_file data_file);
  12. use OpenSSL::Test::Utils;
  13. my $test_name = "test_store";
  14. setup($test_name);
  15. my $mingw = config('target') =~ m|^mingw|;
  16. my $use_md5 = !disabled("md5");
  17. my $use_des = !disabled("des"); # also affects 3des and pkcs12 app
  18. my $use_dsa = !disabled("dsa");
  19. my $use_ecc = !disabled("ec");
  20. my @noexist_files =
  21. ( "test/blahdiblah.pem",
  22. "test/blahdibleh.der" );
  23. my @src_files =
  24. ( "test/testx509.pem",
  25. "test/testrsa.pem",
  26. "test/testrsapub.pem",
  27. "test/testcrl.pem",
  28. "apps/server.pem" );
  29. my @generated_files =
  30. (
  31. ### generated from the source files
  32. "testx509.der",
  33. "testrsa.der",
  34. "testrsapub.der",
  35. "testcrl.der",
  36. ### generated locally
  37. "rsa-key-pkcs1.pem", "rsa-key-pkcs1.der",
  38. "rsa-key-pkcs1-aes128.pem",
  39. "rsa-key-pkcs8.pem", "rsa-key-pkcs8.der",
  40. "rsa-key-pkcs8-pbes2-sha1.pem", "rsa-key-pkcs8-pbes2-sha1.der",
  41. "rsa-key-pkcs8-pbes2-sha256.pem", "rsa-key-pkcs8-pbes2-sha256.der",
  42. );
  43. push(@generated_files, (
  44. "rsa-key-pkcs8-pbes1-sha1-3des.pem", "rsa-key-pkcs8-pbes1-sha1-3des.der",
  45. )) if $use_des;
  46. push(@generated_files, (
  47. "rsa-key-sha1-3des-sha1.p12", "rsa-key-sha1-3des-sha256.p12",
  48. "rsa-key-aes256-cbc-sha256.p12",
  49. "rsa-key-md5-des-sha1.p12",
  50. "rsa-key-aes256-cbc-md5-des-sha256.p12"
  51. )) if $use_des;
  52. push(@generated_files, (
  53. "rsa-key-pkcs8-pbes1-md5-des.pem", "rsa-key-pkcs8-pbes1-md5-des.der"
  54. )) if $use_md5 && $use_des;
  55. push(@generated_files, (
  56. "dsa-key-pkcs1.pem", "dsa-key-pkcs1.der",
  57. "dsa-key-pkcs1-aes128.pem",
  58. "dsa-key-pkcs8.pem", "dsa-key-pkcs8.der",
  59. "dsa-key-pkcs8-pbes2-sha1.pem", "dsa-key-pkcs8-pbes2-sha1.der",
  60. )) if $use_dsa;
  61. push(@generated_files, "dsa-key-aes256-cbc-sha256.p12") if $use_dsa && $use_des;
  62. push(@generated_files, (
  63. "ec-key-pkcs1.pem", "ec-key-pkcs1.der",
  64. "ec-key-pkcs1-aes128.pem",
  65. "ec-key-pkcs8.pem", "ec-key-pkcs8.der",
  66. "ec-key-pkcs8-pbes2-sha1.pem", "ec-key-pkcs8-pbes2-sha1.der",
  67. )) if $use_ecc;
  68. push(@generated_files, "ec-key-aes256-cbc-sha256.p12") if $use_ecc && $use_des;
  69. my %generated_file_files =
  70. $^O eq 'linux'
  71. ? ( "test/testx509.pem" => "file:testx509.pem",
  72. "test/testrsa.pem" => "file:testrsa.pem",
  73. "test/testrsapub.pem" => "file:testrsapub.pem",
  74. "test/testcrl.pem" => "file:testcrl.pem",
  75. "apps/server.pem" => "file:server.pem" )
  76. : ();
  77. my @noexist_file_files =
  78. ( "file:blahdiblah.pem",
  79. "file:test/blahdibleh.der" );
  80. # There is more than one method to get a 'file:' loader.
  81. # The default is a built-in provider implementation.
  82. # However, there is also an engine, specially for testing purposes.
  83. #
  84. # @methods is a collection of extra 'openssl storeutl' arguments used to
  85. # try the different methods.
  86. my @methods;
  87. push @methods, [qw(-provider default -provider legacy)];
  88. push @methods, [qw(-engine loader_attic)]
  89. unless disabled('dynamic-engine') || disabled('deprecated-3.0');
  90. my $n = scalar @methods
  91. * ( (3 * scalar @noexist_files)
  92. + (6 * scalar @src_files)
  93. + (4 * scalar @generated_files)
  94. + (scalar keys %generated_file_files)
  95. + (scalar @noexist_file_files)
  96. + 3
  97. + 11 );
  98. plan skip_all => "No plan" if $n == 0;
  99. plan tests => $n;
  100. indir "store_$$" => sub {
  101. SKIP:
  102. {
  103. init() or die "init failed";
  104. my $rehash = init_rehash();
  105. foreach my $method (@methods) {
  106. my @storeutl = ( qw(openssl storeutl), @$method );
  107. foreach (@noexist_files) {
  108. my $file = srctop_file($_);
  109. ok(!run(app([@storeutl, "-noout", $file])));
  110. ok(!run(app([@storeutl, "-noout", to_abs_file($file)])));
  111. {
  112. local $ENV{MSYS2_ARG_CONV_EXCL} = "file:";
  113. ok(!run(app([@storeutl, "-noout",
  114. to_abs_file_uri($file)])));
  115. }
  116. }
  117. foreach (@src_files) {
  118. my $file = srctop_file($_);
  119. ok(run(app([@storeutl, "-noout", $file])));
  120. ok(run(app([@storeutl, "-noout", to_abs_file($file)])));
  121. SKIP:
  122. {
  123. skip "file: tests disabled on MingW", 4 if $mingw;
  124. ok(run(app([@storeutl, "-noout",
  125. to_abs_file_uri($file)])));
  126. ok(run(app([@storeutl, "-noout",
  127. to_abs_file_uri($file, 0, "")])));
  128. ok(run(app([@storeutl, "-noout",
  129. to_abs_file_uri($file, 0, "localhost")])));
  130. ok(!run(app([@storeutl, "-noout",
  131. to_abs_file_uri($file, 0, "dummy")])));
  132. }
  133. }
  134. foreach (@generated_files) {
  135. ok(run(app([@storeutl, "-noout", "-passin",
  136. "pass:password", $_])));
  137. ok(run(app([@storeutl, "-noout", "-passin",
  138. "pass:password", to_abs_file($_)])));
  139. SKIP:
  140. {
  141. skip "file: tests disabled on MingW", 2 if $mingw;
  142. ok(run(app([@storeutl, "-noout", "-passin",
  143. "pass:password", to_abs_file_uri($_)])));
  144. ok(!run(app([@storeutl, "-noout", "-passin",
  145. "pass:password", to_file_uri($_)])));
  146. }
  147. }
  148. foreach (values %generated_file_files) {
  149. SKIP:
  150. {
  151. skip "file: tests disabled on MingW", 1 if $mingw;
  152. ok(run(app([@storeutl, "-noout", $_])));
  153. }
  154. }
  155. foreach (@noexist_file_files) {
  156. SKIP:
  157. {
  158. skip "file: tests disabled on MingW", 1 if $mingw;
  159. ok(!run(app([@storeutl, "-noout", $_])));
  160. }
  161. }
  162. {
  163. my $dir = srctop_dir("test", "certs");
  164. ok(run(app([@storeutl, "-noout", $dir])));
  165. ok(run(app([@storeutl, "-noout", to_abs_file($dir, 1)])));
  166. SKIP:
  167. {
  168. skip "file: tests disabled on MingW", 1 if $mingw;
  169. ok(run(app([@storeutl, "-noout",
  170. to_abs_file_uri($dir, 1)])));
  171. }
  172. }
  173. ok(!run(app([@storeutl, '-noout',
  174. '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
  175. srctop_file('test', 'testx509.pem')])),
  176. "Checking that -subject can't be used with a single file");
  177. ok(run(app([@storeutl, '-certs', '-noout',
  178. srctop_file('test', 'testx509.pem')])),
  179. "Checking that -certs returns 1 object on a certificate file");
  180. ok(run(app([@storeutl, '-certs', '-noout',
  181. srctop_file('test', 'testcrl.pem')])),
  182. "Checking that -certs returns 0 objects on a CRL file");
  183. ok(run(app([@storeutl, '-crls', '-noout',
  184. srctop_file('test', 'testx509.pem')])),
  185. "Checking that -crls returns 0 objects on a certificate file");
  186. ok(run(app([@storeutl, '-crls', '-noout',
  187. srctop_file('test', 'testcrl.pem')])),
  188. "Checking that -crls returns 1 object on a CRL file");
  189. SKIP: {
  190. skip "failed rehash initialisation", 6 unless $rehash;
  191. # subject from testx509.pem:
  192. # '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert'
  193. # issuer from testcrl.pem:
  194. # '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority'
  195. ok(run(app([@storeutl, '-noout',
  196. '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
  197. catdir(curdir(), 'rehash')])));
  198. ok(run(app([@storeutl, '-noout',
  199. '-subject',
  200. '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
  201. catdir(curdir(), 'rehash')])));
  202. ok(run(app([@storeutl, '-noout', '-certs',
  203. '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
  204. catdir(curdir(), 'rehash')])));
  205. ok(run(app([@storeutl, '-noout', '-crls',
  206. '-subject', '/C=AU/ST=QLD/CN=SSLeay\/rsa test cert',
  207. catdir(curdir(), 'rehash')])));
  208. ok(run(app([@storeutl, '-noout', '-certs',
  209. '-subject',
  210. '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
  211. catdir(curdir(), 'rehash')])));
  212. ok(run(app([@storeutl, '-noout', '-crls',
  213. '-subject',
  214. '/C=US/O=RSA Data Security, Inc./OU=Secure Server Certification Authority',
  215. catdir(curdir(), 'rehash')])));
  216. }
  217. }
  218. }
  219. }, create => 1, cleanup => 1;
  220. sub init {
  221. my $cnf = srctop_file('test', 'ca-and-certs.cnf');
  222. my $cakey = srctop_file('test', 'certs', 'ca-key.pem');
  223. my @std_args = qw(-provider default -provider legacy);
  224. return (
  225. # rsa-key-pkcs1.pem
  226. run(app(["openssl", "pkey", @std_args,
  227. "-in", data_file("rsa-key-2432.pem"),
  228. "-out", "rsa-key-pkcs1.pem"]))
  229. # rsa-key-pkcs1-aes128.pem
  230. && run(app(["openssl", "rsa", @std_args,
  231. "-passout", "pass:password", "-aes128",
  232. "-in", "rsa-key-pkcs1.pem",
  233. "-out", "rsa-key-pkcs1-aes128.pem"]))
  234. # dsa-key-pkcs1.pem
  235. && (!$use_dsa
  236. || run(app(["openssl", "gendsa", @std_args,
  237. "-out", "dsa-key-pkcs1.pem",
  238. data_file("dsaparam.pem")])))
  239. # dsa-key-pkcs1-aes128.pem
  240. && (!$use_dsa
  241. || run(app(["openssl", "dsa", @std_args,
  242. "-passout", "pass:password", "-aes128",
  243. "-in", "dsa-key-pkcs1.pem",
  244. "-out", "dsa-key-pkcs1-aes128.pem"])))
  245. # ec-key-pkcs1.pem (one might think that 'genec' would be practical)
  246. && (!$use_ecc
  247. || run(app(["openssl", "ecparam", @std_args,
  248. "-genkey",
  249. "-name", "prime256v1",
  250. "-out", "ec-key-pkcs1.pem"])))
  251. # ec-key-pkcs1-aes128.pem
  252. && (!$use_ecc
  253. || run(app(["openssl", "ec", @std_args,
  254. "-passout", "pass:password", "-aes128",
  255. "-in", "ec-key-pkcs1.pem",
  256. "-out", "ec-key-pkcs1-aes128.pem"])))
  257. # *-key-pkcs8.pem
  258. && runall(sub {
  259. my $dstfile = shift;
  260. (my $srcfile = $dstfile)
  261. =~ s/-key-pkcs8\.pem$/-key-pkcs1.pem/i;
  262. run(app(["openssl", "pkcs8", @std_args,
  263. "-topk8", "-nocrypt",
  264. "-in", $srcfile, "-out", $dstfile]));
  265. }, grep(/-key-pkcs8\.pem$/, @generated_files))
  266. # *-key-pkcs8-pbes1-sha1-3des.pem
  267. && runall(sub {
  268. my $dstfile = shift;
  269. (my $srcfile = $dstfile)
  270. =~ s/-key-pkcs8-pbes1-sha1-3des\.pem$
  271. /-key-pkcs8.pem/ix;
  272. run(app(["openssl", "pkcs8", @std_args,
  273. "-topk8",
  274. "-passout", "pass:password",
  275. "-v1", "pbeWithSHA1And3-KeyTripleDES-CBC",
  276. "-in", $srcfile, "-out", $dstfile]));
  277. }, grep(/-key-pkcs8-pbes1-sha1-3des\.pem$/, @generated_files))
  278. # *-key-pkcs8-pbes1-md5-des.pem
  279. && runall(sub {
  280. my $dstfile = shift;
  281. (my $srcfile = $dstfile)
  282. =~ s/-key-pkcs8-pbes1-md5-des\.pem$
  283. /-key-pkcs8.pem/ix;
  284. run(app(["openssl", "pkcs8", @std_args,
  285. "-topk8",
  286. "-passout", "pass:password",
  287. "-v1", "pbeWithSHA1And3-KeyTripleDES-CBC",
  288. "-in", $srcfile, "-out", $dstfile]));
  289. }, grep(/-key-pkcs8-pbes1-md5-des\.pem$/, @generated_files))
  290. # *-key-pkcs8-pbes2-sha1.pem
  291. && runall(sub {
  292. my $dstfile = shift;
  293. (my $srcfile = $dstfile)
  294. =~ s/-key-pkcs8-pbes2-sha1\.pem$
  295. /-key-pkcs8.pem/ix;
  296. run(app(["openssl", "pkcs8", @std_args,
  297. "-topk8",
  298. "-passout", "pass:password",
  299. "-v2", "aes256", "-v2prf", "hmacWithSHA1",
  300. "-in", $srcfile, "-out", $dstfile]));
  301. }, grep(/-key-pkcs8-pbes2-sha1\.pem$/, @generated_files))
  302. # *-key-pkcs8-pbes2-sha1.pem
  303. && runall(sub {
  304. my $dstfile = shift;
  305. (my $srcfile = $dstfile)
  306. =~ s/-key-pkcs8-pbes2-sha256\.pem$
  307. /-key-pkcs8.pem/ix;
  308. run(app(["openssl", "pkcs8", @std_args,
  309. "-topk8",
  310. "-passout", "pass:password",
  311. "-v2", "aes256", "-v2prf", "hmacWithSHA256",
  312. "-in", $srcfile, "-out", $dstfile]));
  313. }, grep(/-key-pkcs8-pbes2-sha256\.pem$/, @generated_files))
  314. # *-cert.pem (intermediary for the .p12 inits)
  315. && run(app(["openssl", "req", "-x509", @std_args,
  316. "-config", $cnf, "-noenc",
  317. "-key", $cakey, "-out", "cacert.pem"]))
  318. && runall(sub {
  319. my $srckey = shift;
  320. (my $dstfile = $srckey) =~ s|-key-pkcs8\.|-cert.|;
  321. (my $csr = $dstfile) =~ s|\.pem|.csr|;
  322. (run(app(["openssl", "req", "-new", @std_args,
  323. "-config", $cnf, "-section", "userreq",
  324. "-key", $srckey, "-out", $csr]))
  325. &&
  326. run(app(["openssl", "x509", @std_args,
  327. "-days", "3650",
  328. "-CA", "cacert.pem",
  329. "-CAkey", $cakey,
  330. "-set_serial", time(), "-req",
  331. "-in", $csr, "-out", $dstfile])));
  332. }, grep(/-key-pkcs8\.pem$/, @generated_files))
  333. # *.p12
  334. && runall(sub {
  335. my $dstfile = shift;
  336. my ($type, $certpbe_index, $keypbe_index,
  337. $macalg_index) =
  338. $dstfile =~ m{^(.*)-key-(?|
  339. # cert and key PBE are same
  340. () #
  341. ([^-]*-[^-]*)- # key & cert PBE
  342. ([^-]*) # MACalg
  343. |
  344. # cert and key PBE are not same
  345. ([^-]*-[^-]*)- # cert PBE
  346. ([^-]*-[^-]*)- # key PBE
  347. ([^-]*) # MACalg
  348. )\.}x;
  349. if (!$certpbe_index) {
  350. $certpbe_index = $keypbe_index;
  351. }
  352. my $srckey = "$type-key-pkcs8.pem";
  353. my $srccert = "$type-cert.pem";
  354. my %pbes =
  355. (
  356. "sha1-3des" => "pbeWithSHA1And3-KeyTripleDES-CBC",
  357. "md5-des" => "pbeWithMD5AndDES-CBC",
  358. "aes256-cbc" => "AES-256-CBC",
  359. );
  360. my %macalgs =
  361. (
  362. "sha1" => "SHA1",
  363. "sha256" => "SHA256",
  364. );
  365. my $certpbe = $pbes{$certpbe_index};
  366. my $keypbe = $pbes{$keypbe_index};
  367. my $macalg = $macalgs{$macalg_index};
  368. if (!defined($certpbe) || !defined($keypbe)
  369. || !defined($macalg)) {
  370. print STDERR "Cert PBE for $certpbe_index not defined\n"
  371. unless defined $certpbe;
  372. print STDERR "Key PBE for $keypbe_index not defined\n"
  373. unless defined $keypbe;
  374. print STDERR "MACALG for $macalg_index not defined\n"
  375. unless defined $macalg;
  376. print STDERR "(destination file was $dstfile)\n";
  377. return 0;
  378. }
  379. run(app(["openssl", "pkcs12", @std_args,
  380. "-inkey", $srckey,
  381. "-in", $srccert, "-passout", "pass:password",
  382. "-chain", "-CAfile", "cacert.pem",
  383. "-export", "-macalg", $macalg,
  384. "-certpbe", $certpbe, "-keypbe", $keypbe,
  385. "-out", $dstfile]));
  386. }, grep(/\.p12/, @generated_files))
  387. # *.der (the end all init)
  388. && runall(sub {
  389. my $dstfile = shift;
  390. (my $srcfile = $dstfile) =~ s/\.der$/.pem/i;
  391. if (! -f $srcfile) {
  392. $srcfile = srctop_file("test", $srcfile);
  393. }
  394. my $infh;
  395. unless (open $infh, $srcfile) {
  396. return 0;
  397. }
  398. my $l;
  399. while (($l = <$infh>) !~ /^-----BEGIN\s/
  400. || $l =~ /^-----BEGIN.*PARAMETERS-----/) {
  401. }
  402. my $b64 = "";
  403. while (($l = <$infh>) !~ /^-----END\s/) {
  404. $l =~ s|\R$||;
  405. $b64 .= $l unless $l =~ /:/;
  406. }
  407. close $infh;
  408. my $der = decode_base64($b64);
  409. unless (length($b64) / 4 * 3 - length($der) < 3) {
  410. print STDERR "Length error, ",length($b64),
  411. " bytes of base64 became ",length($der),
  412. " bytes of der? ($srcfile => $dstfile)\n";
  413. return 0;
  414. }
  415. my $outfh;
  416. unless (open $outfh, ">:raw", $dstfile) {
  417. return 0;
  418. }
  419. print $outfh $der;
  420. close $outfh;
  421. return 1;
  422. }, grep(/\.der$/, @generated_files))
  423. && runall(sub {
  424. my $srcfile = shift;
  425. my $dstfile = $generated_file_files{$srcfile};
  426. unless (copy srctop_file($srcfile), $dstfile) {
  427. warn "$!\n";
  428. return 0;
  429. }
  430. return 1;
  431. }, keys %generated_file_files)
  432. );
  433. }
  434. sub init_rehash {
  435. return (
  436. mkdir(catdir(curdir(), 'rehash'))
  437. && copy(srctop_file('test', 'testx509.pem'),
  438. catdir(curdir(), 'rehash'))
  439. && copy(srctop_file('test', 'testcrl.pem'),
  440. catdir(curdir(), 'rehash'))
  441. && run(app(['openssl', 'rehash', catdir(curdir(), 'rehash')]))
  442. );
  443. }
  444. sub runall {
  445. my ($function, @items) = @_;
  446. foreach (@items) {
  447. return 0 unless $function->($_);
  448. }
  449. return 1;
  450. }
  451. # According to RFC8089, a relative file: path is invalid. We still produce
  452. # them for testing purposes.
  453. sub to_file_uri {
  454. my ($file, $isdir, $authority) = @_;
  455. my $vol;
  456. my $dir;
  457. die "to_file_uri: No file given\n" if !defined($file) || $file eq '';
  458. ($vol, $dir, $file) = File::Spec->splitpath($file, $isdir // 0);
  459. # Make sure we have a Unix style directory.
  460. $dir = join('/', File::Spec->splitdir($dir));
  461. # Canonicalise it (note: it seems to be only needed on Unix)
  462. while (1) {
  463. my $newdir = $dir;
  464. $newdir =~ s|/[^/]*[^/\.]+[^/]*/\.\./|/|g;
  465. last if $newdir eq $dir;
  466. $dir = $newdir;
  467. }
  468. # Take care of the corner cases the loop can't handle, and that $dir
  469. # ends with a / unless it's empty
  470. $dir =~ s|/[^/]*[^/\.]+[^/]*/\.\.$|/|;
  471. $dir =~ s|^[^/]*[^/\.]+[^/]*/\.\./|/|;
  472. $dir =~ s|^[^/]*[^/\.]+[^/]*/\.\.$||;
  473. if ($isdir // 0) {
  474. $dir =~ s|/$|| if $dir ne '/';
  475. } else {
  476. $dir .= '/' if $dir ne '' && $dir !~ m|/$|;
  477. }
  478. # If the file system has separate volumes (at present, Windows and VMS)
  479. # we need to handle them. In URIs, they are invariably the first
  480. # component of the path, which is always absolute.
  481. # On VMS, user:[foo.bar] translates to /user/foo/bar
  482. # On Windows, c:\Users\Foo translates to /c:/Users/Foo
  483. if ($vol ne '') {
  484. $vol =~ s|:||g if ($^O eq "VMS");
  485. $dir = '/' . $dir if $dir ne '' && $dir !~ m|^/|;
  486. $dir = '/' . $vol . $dir;
  487. }
  488. $file = $dir . $file;
  489. return "file://$authority$file" if defined $authority;
  490. return "file:$file";
  491. }
  492. sub to_abs_file {
  493. my ($file) = @_;
  494. return File::Spec->rel2abs($file);
  495. }
  496. sub to_abs_file_uri {
  497. my ($file, $isdir, $authority) = @_;
  498. die "to_abs_file_uri: No file given\n" if !defined($file) || $file eq '';
  499. return to_file_uri(to_abs_file($file), $isdir, $authority);
  500. }