מדיניות DecodeJWS

מוצג המסמך של Apigee Edge.
עוברים אל מסמכי תיעוד של Apigee X.
מידע

מה

מפענח את כותרת ה-JWS ללא אימות החתימה ב-JWS, וכותב כל כותרת במשתנה הזרימה, המדיניות הזו שימושית במיוחד כשמשתמשים בה בשילוב עם המדיניות לאימות JWS. כשהערך של כותרת מתוך ה-JWS חייב להיות ידוע לפני אימות החתימה של ה-JWS.

JWS יכול לכלול מטען ייעודי (payload) מצורף, כמו בדוגמה הבאה:

header.payload.signature

לחלופין, ה-JWS יכול להשמיט את המטען הייעודי (payload), שנקרא מטען ייעודי (payload) מנותק, ולהיות בפורמט הבא:

header..signature

המדיניות DecodeJWS עובדת עם שני הטפסים כי היא מפענחת רק את חלק הכותרת של ה-JWS. המדיניות DecodeJWS פועלת גם בלי קשר לאלגוריתם ששימש לחתימה על ה-JWS.

למבוא מפורט, אתם יכולים לעיין בסקירה הכללית של המדיניות של JWS ו-JWT וסקירה כללית על הפורמט של JWS.

וידאו

בסרטון קצר זה מוסבר איך לפענח את הקוד של JWT. אומנם הסרטון הזה ספציפיים ל-JWT, רבים מהמושגים זהים ב-JWS.

דוגמה: Decode a JWS

המדיניות הבאה מפענחת JWS שנמצא במשתנה הזרימה var.JWS. הזה חייב להיות קיים ולהכיל ערך JWS בר-קיימא (ניתן לפענוח). המדיניות יכולה לקבל את ה-JWS כל משתנה של זרימה.

<DecodeJWS name="JWS-Decode-HS256">
    <DisplayName>JWS Verify HS256</DisplayName>
    <Source>var.JWS</Source>
</DecodeJWS>

לכל כותרת בחלק הכותרת של ה-JWS, המדיניות מגדירה משתנה זרימה בשם:

jws.policy-name.header.header-name

אם ל-JWS מצורף מטען ייעודי (payload), הוא מגדיר את ה-jws.policy-name.header.payload עובר במטען הייעודי (payload). במטען ייעודי (payload) מנותק, השדה payload ריק. במאמר משתני זרימה תוכלו למצוא רשימה מלאה של המשתנים שהוגדרו במדיניות הזו.

מסמך עזר של רכיב לפענוח קוד של JWS

בחומר העזר בנושא המדיניות מתוארים הרכיבים והמאפיינים של מדיניות 'פענוח קוד של JWS'.

מאפיינים החלה על הרכיב ברמה העליונה

<DecodeJWS name="JWS" continueOnError="false" enabled="true" async="false">

המאפיינים הבאים משותפים לכל רכיבי ההורה של המדיניות.

מאפיין תיאור ברירת מחדל נוכחות
שם השם הפנימי של המדיניות. תווים שבהם אפשר להשתמש בשם מוגבלים ל: A-Z0-9._\-$ % עם זאת, בממשק המשתמש לניהול Edge אוכפים פקודות נוספות הגבלות, כגון הסרה אוטומטית של תווים שאינם אלפאנומריים.

אפשר להשתמש ברכיב <displayname></displayname> כדי להוסיף תווית למדיניות בעורך ה-Proxy של ממשק המשתמש לניהול בשפה טבעית אחרת שם.

לא רלוונטי חובה
continueOnError צריך להגדיר את הערך false כדי להחזיר שגיאה כשמדיניות נכשלת. המצב הזה צפוי של רוב כללי המדיניות.

יש להגדיר ל-true כדי שביצוע התהליך יימשך גם לאחר המדיניות נכשל.

false אופציונלי
פעיל צריך להגדיר את הערך true כדי לאכוף את המדיניות.

הגדרת הערך false כ'כיבוי' המדיניות. המדיניות לא תיאכף גם אם הוא נשאר מחובר לזרימה.

true אופציונלי
אסינכרוני המאפיין הזה הוצא משימוש. false הוצא משימוש

&lt;DisplayName&gt;

<DisplayName>Policy Display Name</DisplayName>

שימוש בנוסף למאפיין השם כדי להוסיף תווית למדיניות בעורך ה-Proxy של ממשק המשתמש לניהול בשם אחר בשפה טבעית.

ברירת מחדל אם משמיטים את הרכיב הזה, המערכת תשתמש בערך של מאפיין השם של המדיניות.
נוכחות אופציונלי
סוג מחרוזת

&lt;Source&gt;

<Source>JWS-variable</Source>

אם השדה הזה קיים, הוא מציין את משתנה הזרימה שבו המדיניות מצפה למצוא את ה-JWS לפענח אותו.

ברירת מחדל request.header.authorization (מידע חשוב מופיע בהערה שלמעלה מידע על ברירת המחדל).
נוכחות אופציונלי
סוג מחרוזת
ערכים חוקיים שם משתנה של זרימה ב-Edge

Flow variables

Upon success, the Verify JWS and Decode JWS policies set context variables according to this pattern:

jws.{policy_name}.{variable_name}

For example, if the policy name is verify-jws, then the policy will store the algorithm specified in the JWS to this context variable: jws.verify-jws.header.algorithm

Variable name Description
decoded.header.name The JSON-parsable value of a header in the payload. One variable is set for every header in the payload. While you can also use the header.name flow variables, this is the recommended variable to use to access a header.
header.algorithm The signing algorithm used on the JWS. For example, RS256, HS384, and so on. See (Algorithm) Header Parameter for more.
header.kid The Key ID, if added when the JWS was generated. See also "Using a JSON Web Key Set (JWKS)" at JWT and JWS policies overview to verify a JWS. See (Key ID) Header Parameter for more.
header.type The header type value. See (Type) Header Parameter for more.
header.name The value of the named header (standard or additional). One of these will be set for every additional header in the header portion of the JWS.
header-json The header in JSON format.
payload The JWS payload if the JWS has an attached payload. For a detached payload, this variable is empty.
valid In the case of VerifyJWS, this variable will be true when the signature is verified, and the current time is before the token expiry, and after the token notBefore value, if they are present. Otherwise false.

In the case of DecodeJWS, this variable is not set.

התייחסות לשגיאות

This section describes the fault codes and error messages that are returned and fault variables that are set by Edge when this policy triggers an error. This information is important to know if you are developing fault rules to handle faults. To learn more, see What you need to know about policy errors and Handling faults.

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Occurs when
steps.jws.FailedToDecode 401 The policy was unable to decode the JWS. The JWS is possibly corrupted.
steps.jws.FailedToResolveVariable 401 Occurs when the flow variable specified in the <Source> element of the policy does not exist.
steps.jws.InvalidClaim 401 For a missing claim or claim mismatch, or a missing header or header mismatch.
steps.jws.InvalidJsonFormat 401 Invalid JSON found in the JWS header.
steps.jws.InvalidJws 401 This error occurs when the JWS signature verification fails.
steps.jws.InvalidPayload 401 The JWS payload is invalid.
steps.jws.InvalidSignature 401 <DetachedContent> is omitted and the JWS has a detached content payload.
steps.jws.MissingPayload 401 The JWS payload is missing.
steps.jws.NoAlgorithmFoundInHeader 401 Occurs when the JWS omits the algorithm header.
steps.jws.UnknownException 401 An unknown exception occurred.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Occurs when
InvalidAlgorithm The only valid values are: RS256, RS384, RS512, PS256, PS384, PS512, ES256, ES384, ES512, HS256, HS384, HS512.

EmptyElementForKeyConfiguration

FailedToResolveVariable

InvalidConfigurationForActionAndAlgorithmFamily

InvalidConfigurationForVerify

InvalidEmptyElement

InvalidFamiliesForAlgorithm

InvalidKeyConfiguration

InvalidNameForAdditionalClaim

InvalidNameForAdditionalHeader

InvalidPublicKeyId

InvalidPublicKeyValue

InvalidSecretInConfig

InvalidTypeForAdditionalClaim

InvalidTypeForAdditionalHeader

InvalidValueForElement

InvalidValueOfArrayAttribute

InvalidVariableNameForSecret

MissingConfigurationElement

MissingElementForKeyConfiguration

MissingNameForAdditionalClaim

MissingNameForAdditionalHeader

Other possible deployment errors.

משתני כשל

המשתנים האלה מוגדרים כשמתרחשת שגיאה בסביבת זמן הריצה. מידע נוסף זמין במאמר מה צריך לדעת? על שגיאות שקשורות למדיניות.

משתנים איפה דוגמה
fault.name="fault_name" fault_name הוא שם השגיאה, כפי שמצוין בטבלה שגיאות זמן ריצה שלמעלה. שם השגיאה הוא החלק האחרון בקוד השגיאה. fault.name Matches "TokenExpired"
JWS.failed כל כללי המדיניות של JWS מגדירים את אותו משתנה במקרה של כשל. jws.JWS-Policy.failed = true

דוגמה לתגובת שגיאה

לטיפול בשגיאות, השיטה המומלצת היא להעתיק את החלק errorcode של השגיאה תשובה. אין להסתמך על הטקסט שבfaultstring, כי הוא עשוי להשתנות.

דוגמה לכלל שגוי

<FaultRules>
    <FaultRule name="JWS Policy Errors">
        <Step>
            <Name>JavaScript-1</Name>
            <Condition>(fault.name Matches "TokenExpired")</Condition>
        </Step>
        <Condition>JWS.failed=true</Condition>
    </FaultRule>
</FaultRules>