diff --git a/config-templates/config.php b/config-templates/config.php
index a864e976f61a2971a17acd193517a0b9b6826cf2..85942703ea9710d21b92d8891d9d4e70450e7960 100644
--- a/config-templates/config.php
+++ b/config-templates/config.php
@@ -544,7 +544,13 @@ $config = array (
 	'metadata.sign.privatekey_pass' => NULL,
 	'metadata.sign.certificate' => NULL,
 
-);
 
+	/*
+	 * Proxy to use for retrieving URLs.
+	 *
+	 * Example:
+	 *   'proxy' => 'tcp://proxy.example.com:5100'
+	 */
+	'proxy' => NULL,
 
-?>
\ No newline at end of file
+);
diff --git a/lib/SimpleSAML/Utilities.php b/lib/SimpleSAML/Utilities.php
index de336154b8960e0afb751b096fd480491d388a9c..46a0ea887e7e6d148fd8b0efc2d59b47c67aa52c 100644
--- a/lib/SimpleSAML/Utilities.php
+++ b/lib/SimpleSAML/Utilities.php
@@ -1950,6 +1950,39 @@ class SimpleSAML_Utilities {
 		}
 	}
 
-}
 
-?>
\ No newline at end of file
+	/**
+	 * Helper function to retrieve a file or URL with proxy support.
+	 *
+	 * An exception will be thrown if we are unable to retrieve the data.
+	 *
+	 * @param string $path  The path or URL we should fetch.
+	 * @param array $context  Extra context options. This parameter is optional.
+	 * @return string  The data we fetched.
+	 */
+	public static function fetch($path, $context = array()) {
+		assert('is_string($path)');
+
+		$config = SimpleSAML_Configuration::getInstance();
+
+		$proxy = $config->getString('proxy', NULL);
+		if ($proxy !== NULL) {
+			if (!isset($context['http']['proxy'])) {
+				$context['http']['proxy'] = $proxy;
+			}
+			if (!isset($context['http']['request_fulluri'])) {
+				$context['http']['request_fulluri'] = TRUE;
+			}
+		}
+
+		$context = stream_context_create($context);
+
+		$data = file_get_contents($path, FALSE, $context);
+		if ($data === FALSE) {
+			throw new SimpleSAML_Error_Exception('Error fetching ' . var_export($path, TRUE) . ':' . self::getLastError());
+		}
+
+		return $data;
+	}
+
+}