Apache2-ClickPath

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN

280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
      "ClickPathSecretIV" is a simple string of arbitrary length. The
      first 8 bytes of its MD5 digest are used as initialization vector.
      If omitted the string "abcd1234" is the IV.
 
      "ClickPathSecret" is given as "http:", "https:", "file:" or "data:"
      URL. Thus the secret can be stored directly as data-URL in the
      httpd.conf or in a separate file on the local disk or on a possibly
      secured server. To enable all modes of accessing the WEB the
      http(s)-URL syntax is a bit extented. Maybe you have already used
      "http://user:password@server.tld/...". Many browsers allow this
      syntax to specify a username and password for HTTP authentication.
      But how about proxies, SSL-authentication etc? Well, add another
      colon (:) after the password and append a semicolon (;) delimited
      list of "key=value" pairs. The special characters (@:;\) can be
      quoted with a backslash (\). In fact, all characters can be quoted.
      Thus, "\a" and "a" produce the same string "a".
 
      The following keys are defined:
 
      https_proxy
      https_proxy_username
      https_proxy_password
      https_version
      https_cert_file
      https_key_file
      https_ca_file
      https_ca_dir
      https_pkcs12_file
      https_pkcs12_password
        their meaning is defined in Crypt::SSLeay.
 
      http_proxy
      http_proxy_username
      http_proxy_password
        these are passed to LWP::UserAgent.
 
        Remember a HTTP-proxy is accessed with the GET or POST, ...
        methods whereas a HTTPS-proxy is accessed with CONNECT. Don't mix
        them, see Crypt::SSLeay.
 
      Examples
 
       ClickPathSecret https://john:a\@b\;c\::https_ca_file=/my/ca.pem@secrethost.tld/bin/secret.pl?host=me
 
      fetches the secret from
      "https://secrethost.tdl/bin/secret.pl?host=me" using "john" as
      username and "a@b;c:" as password. The server certificate of
      secrethost.tld is verified against the CA certificate found in
      "/my/ca.pem".
 
       ClickPathSecret https://::https_pkcs12_file=/my/john.p12;https_pkcs12_password=a\@b\;c\:;https_ca_file=/my/ca.pem@secrethost.tld/bin/secret.pl?host=me
 
      fetches the secret again from
      "https://secrethost.tdl/bin/secret.pl?host=me" using "/my/john.p12"
      as client certificate with "https://metacpan.org/pod/a">a@b;c:" as password. The server
      certificate of secrethost.tld is again verified against the CA
      certificate found in "/my/ca.pem".
 
       ClickPathSecret data:,password:very%20secret%20password
 
      here a data-URL is used that produces the content "password:very
      secret password".
 
      The URL's content is fetched by LWP::UserAgent once at server
      startup.
 
      Its content defines the secret either in binary form or as string of
      hexadecimal characters or as a password. If it starts with "https://metacpan.org/pod/binary:">binary:"
      the rest of the content is taken as is as the key. If it starts with
      "hex:" "pack( 'H*', $arg )" is used to convert it to binary. If it
      starts with "https://metacpan.org/pod/password:">password:" or with neither of them the MD5 digest of
      the rest of the content is used as secret.
 
      The Blowfish algorithm allows up to 56 bytes as secret. In hex and
      binary mode the starting 56 bytes are used. You can specify more
      bytes but they won't be regarded. In password mode the MD5 algorithm
      produces 16 bytes long secret.
 
Working with a load balancer
  Most load balancers are able to map a request to a particular machine
  based on a part of the request URI. They look for a prefix followed by a
  given number of characters or until a suffix is found. The string
  between identifies the machine to route the request to.
 
  The name set with "https://metacpan.org/pod/ClickPathMachine">ClickPathMachine" can be used by a load balancer. It
  is immediately following the session prefix and finished by a single

lib/Apache2/ClickPath.pm  view on Meta::CPAN

1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
the key, C<ClickPathSecretIV> the initialization vector.
 
C<ClickPathSecretIV> is a simple string of arbitrary length. The first 8
bytes of its MD5 digest are used as initialization vector. If omitted the
string C<abcd1234> is the IV.
 
C<ClickPathSecret> is given as C<http:>, C<https:>, C<file:> or C<data:> URL.
Thus the secret can be stored directly as data-URL in the httpd.conf or in a
separate file on the local disk or on a possibly secured server. To enable
all modes of accessing the WEB the http(s)-URL syntax is a bit extented.
Maybe you have already used C<http://user:password@server.tld/...>. Many
browsers allow this syntax to specify a username and password for HTTP
authentication. But how about proxies, SSL-authentication etc? Well, add
another colon (:) after the password and append a semicolon (;) delimited
list of C<key=value> pairs. The special characters (@:;\) can be quoted
with a backslash (\). In fact, all characters can be quoted. Thus, C<\a> and
C<a> produce the same string C<a>.
 
The following keys are defined:
 
=over 2
 
=item B<https_proxy>
 
=item B<https_proxy_username>
 
=item B<https_proxy_password>
 
=item B<https_version>
 
=item B<https_cert_file>
 
=item B<https_key_file>
 
=item B<https_ca_file>
 
=item B<https_ca_dir>
 
=item B<https_pkcs12_file>
 
=item B<https_pkcs12_password>
 
their meaning is defined in L<Crypt::SSLeay>.
 
=item B<http_proxy>
 
=item B<http_proxy_username>
 
=item B<http_proxy_password>
 
these are passed to L<LWP::UserAgent>.
 
Remember a HTTP-proxy is accessed with the GET or POST, ... methods whereas
a HTTPS-proxy is accessed with CONNECT. Don't mix them, see L<Crypt::SSLeay>.
 
=back
 
B<Examples>
 
 ClickPathSecret https://john:a\@b\;c\::https_ca_file=/my/ca.pem@secrethost.tld/bin/secret.pl?host=me
 
using C<john> as username and C<a@b;c:> as password. The server certificate
of secrethost.tld is verified against the CA certificate found in
C</my/ca.pem>.
 
 ClickPathSecret https://::https_pkcs12_file=/my/john.p12;https_pkcs12_password=a\@b\;c\:;https_ca_file=/my/ca.pem@secrethost.tld/bin/secret.pl?host=me
 
fetches the secret again from C<https://secrethost.tdl/bin/secret.pl?host=me>
using C</my/john.p12> as client certificate with C<a@b;c:> as password.
The server certificate of secrethost.tld is again verified against the CA
certificate found in C</my/ca.pem>.
 
 ClickPathSecret data:,password:very%20secret%20password
 
here a data-URL is used that produces the content
C<password:very secret password>.
 
The URL's content is fetched by L<LWP::UserAgent> once at server startup.
 
Its content defines the secret either in binary form or as string of
hexadecimal characters or as a password. If it starts with C<binary:> the
rest of the content is taken as is as the key. If it starts with C<hex:>
C<pack( 'H*', $arg )> is used to convert it to binary. If it starts with
C<password:> or with neither of them the MD5 digest of the rest of the
content is used as secret.
 
The Blowfish algorithm allows up to 56 bytes as secret. In hex and binary
mode the starting 56 bytes are used. You can specify more bytes but they
won't be regarded. In password mode the MD5 algorithm produces
16 bytes long secret.
 
=back
 
=head2 Working with a load balancer
 
Most load balancers are able to map a request to a particular machine
based on a part of the request URI. They look for a prefix followed
by a given number of characters or until a suffix is found. The string
between identifies the machine to route the request to.

lib/Apache2/ClickPath/_parse.pm  view on Meta::CPAN

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
    my @auth=split /(?<!\\):/, $2, 3;
    if( length $auth[0] and length $auth[1] ) {
      @ENV{qw{HTTP_USERNAME HTTP_PASSWORD}}=map {s!\\(.)!$1!g; $_} @auth[0,1];
    }
    foreach my $el (split /(?<!\\);/, $auth[2]) {
      $el=~s!\\(.)!$1!g;
      if( $el=~s/https_proxy=//i ) {
        $ENV{HTTPS_PROXY}=$el;
      } elsif( $el=~s/https_proxy_username=//i ) {
        $ENV{HTTPS_PROXY_USERNAME}=$el;
      } elsif( $el=~s/https_proxy_password=//i ) {
        $ENV{HTTPS_PROXY_PASSWORD}=$el;
      } elsif( $el=~s/https_version=//i ) {
        $ENV{HTTPS_VERSION}=$el;
      } elsif( $el=~s/https_cert_file=//i ) {
        $ENV{HTTPS_CERT_FILE}=$el;
      } elsif( $el=~s/https_key_file=//i ) {
        $ENV{HTTPS_KEY_FILE}=$el;
      } elsif( $el=~s/https_ca_file=//i ) {
        $ENV{HTTPS_CA_FILE}=$el;
      } elsif( $el=~s/https_ca_dir=//i ) {
        $ENV{HTTPS_CA_DIR}=$el;
      } elsif( $el=~s/https_pkcs12_file=//i ) {
        $ENV{HTTPS_PKCS12_FILE}=$el;
      } elsif( $el=~s/https_pkcs12_password=//i ) {
        $ENV{HTTPS_PKCS12_PASSWORD}=$el;
      } elsif( $el=~s/http_proxy=//i ) {
        $ua->proxy( http=>$el );
      } elsif( $el=~s/http_proxy_username=//i ) {
        $ENV{HTTP_PROXY_USERNAME}=$el;
      } elsif( $el=~s/http_proxy_password=//i ) {
        $ENV{HTTP_PROXY_PASSWORD}=$el;
      }
    }
  }
  $arg=~s!\\(.)!$1!g if( $arg=~m#^https?://# );
 
  my $resp=$ua->get( $arg );
 
  if( $resp->code==200 ) {
    $arg=$resp->content;
    if( $arg=~s/^binary:// ) {
      # blowfish keys are up to 56 bytes long
      $arg=substr( $arg, 0, 56 ) if( length($arg)>56 );
    } elsif( $arg=~s/^hex:// ) {
      $arg=pack( 'H*', $arg );
      $arg=substr( $arg, 0, 56 ) if( length($arg)>56 );
    } elsif( $arg=~s/^password:// ) {
      $arg=Digest::MD5::md5( $arg );
    } else {
      $arg=Digest::MD5::md5( $arg );
    }
    return $arg;
  } else {
    die "ERROR: ClickPathSecret: Cannot fetch secret from $arg\n";
  }
}



( run in 0.322 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )