Просмотр исходного кода

Add paver mode that emits current period OSL IDs

Rod Hynes 8 лет назад
Родитель
Сommit
29baab725f
2 измененных файлов с 43 добавлено и 0 удалено
  1. 28 0
      psiphon/common/osl/osl.go
  2. 15 0
      psiphon/common/osl/paver/main.go

+ 28 - 0
psiphon/common/osl/osl.go

@@ -890,6 +890,34 @@ func (config *Config) Pave(
 	return paveFiles, nil
 }
 
+// CurrentOSLIDs returns a mapping from each propagation channel ID in the
+// specified scheme to the corresponding current time period, hex-encoded OSL ID.
+func (config *Config) CurrentOSLIDs(schemeIndex int) (map[string]string, error) {
+
+	config.ReloadableFile.RLock()
+	defer config.ReloadableFile.RUnlock()
+
+	if schemeIndex < 0 || schemeIndex >= len(config.Schemes) {
+		return nil, common.ContextError(errors.New("invalid scheme index"))
+	}
+
+	scheme := config.Schemes[schemeIndex]
+	now := time.Now().UTC()
+	oslDuration := scheme.GetOSLDuration()
+	oslTime := scheme.epoch.Add((now.Sub(scheme.epoch) / oslDuration) * oslDuration)
+
+	OSLIDs := make(map[string]string)
+	for _, propagationChannelID := range scheme.PropagationChannelIDs {
+		_, fileSpec, err := makeOSLFileSpec(scheme, propagationChannelID, oslTime)
+		if err != nil {
+			return nil, common.ContextError(err)
+		}
+		OSLIDs[propagationChannelID] = hex.EncodeToString(fileSpec.ID)
+	}
+
+	return OSLIDs, nil
+}
+
 // makeOSLFileSpec creates an OSL file key, splits it according to the
 // scheme's key splits, and sets the OSL ID as its first SLOK ID. The
 // returned key is used to encrypt the OSL payload and then discarded;

+ 15 - 0
psiphon/common/osl/paver/main.go

@@ -60,6 +60,9 @@ func main() {
 		&destinationDirectory, "output", "",
 		"destination directory for output files; when omitted, no files are written (dry run mode)")
 
+	var listScheme int
+	flag.IntVar(&listScheme, "list-scheme", -1, "list current period OSL IDs for specified scheme; no files are written")
+
 	flag.Parse()
 
 	// load config
@@ -76,6 +79,18 @@ func main() {
 		os.Exit(1)
 	}
 
+	if listScheme != -1 {
+		OSLIDs, err := config.CurrentOSLIDs(listScheme)
+		if err != nil {
+			fmt.Printf("failed listing scheme OSL IDs: %s\n", err)
+			os.Exit(1)
+		}
+		for propagationChannelID, OSLID := range OSLIDs {
+			fmt.Printf("%s %s\n", propagationChannelID, OSLID)
+		}
+		return
+	}
+
 	// load key pair
 
 	keyPairPEM, err := ioutil.ReadFile(signingKeyPairFilename)