Hi all,

Till now the get-location-segments.py script does not work against self-signed ssl servers. Now I have worked on the script and made it work even against the untrusted self-signed ssl servers.

Attaching the patch and the log message with this mail. Please share your thoughts.



Thanks and regards
Prabhu
get-location-segments.py script would now work for self-signed ssl servers too

* tools/examples/get-location-segments.py
  (main): added a couple of auth providers to enable authenticating
          against self-signed ssl servers too (in interactive mode).
  (prompt_func_ssl_unknown_cert): new callback function
  (prompt_func_simple_prompt): new callback function

Patch by: Prabhu Gnana Sundar <prabhugs{_AT_}collab.net>
Index: tools/examples/get-location-segments.py
===================================================================
--- tools/examples/get-location-segments.py	(revision 1153033)
+++ tools/examples/get-location-segments.py	(working copy)
@@ -21,6 +21,7 @@
 #
 import sys
 import os
+import getpass
 from svn import client, ra, core
 
 def printer(segment, pool):
@@ -71,6 +72,39 @@
   return url, peg_revision, start_revision, end_revision
 
 
+def prompt_func_ssl_unknown_cert(realm, failures, cert_info, may_save, pool):
+  print "Untrusted cert details are as follows:"
+  print "--------------------------------------"
+  print "Issuer     : " + str(cert_info.issuer_dname)
+  print "Hostname   : " + str(cert_info.hostname)
+  print "ValidFrom  : " + str(cert_info.valid_from)
+  print "ValidUpto  : " + str(cert_info.valid_until)
+  print "Fingerprint: " + str(cert_info.fingerprint)
+  print ""
+  ssl_trust = core.svn_auth_cred_ssl_server_trust_t()
+  if may_save:
+    choice = raw_input( "accept (t)temporarily   (p)permanently: ")
+  else:
+    choice = raw_input( "(r)Reject or accept (t)temporarily: ")
+  if choice == "t" or choice == "T":
+    ssl_trust.may_save = False
+    ssl_trust.accepted_failures = failures
+  if choice == "p" or choice == "P":
+    ssl_trust.may_save = True
+    ssl_trust.accepted_failures = failures
+  else:
+    ssl_trust = None
+  return ssl_trust
+
+def prompt_func_simple_prompt(realm, username, may_save, pool):
+  username = raw_input("username: ")
+  password = getpass.getpass(prompt="password: ")
+  simple_cred = core.svn_auth_cred_simple_t()
+  simple_cred.username = username
+  simple_cred.password = password
+  simple_cred.may_save = False
+  return simple_cred
+
 def main():
   try:
     url, peg_revision, start_revision, end_revision = parse_args(sys.argv[1:])
@@ -94,6 +128,8 @@
   providers = [
     client.get_simple_provider(),
     client.get_username_provider(),
+    core.svn_auth_get_simple_prompt_provider(prompt_func_simple_prompt, 2),
+    core.svn_auth_get_ssl_server_trust_prompt_provider(prompt_func_ssl_unknown_cert),
     client.get_ssl_server_trust_file_provider(),
     client.get_ssl_client_cert_file_provider(),
     client.get_ssl_client_cert_pw_file_provider(),

Reply via email to